Lecture 21_3/29_Kailu Song void Node_destroy(Node *node) { free(node); }
Node *List_elementAt(Node *head, int index);
Node *List_search(Node *head, int v) { while(head != NULL && head -> value != v) { head = head -> next; } return head; }
Node *List_insertBack(Node *head, int value) { Node *node = Node_create(value,NULL); if (head == NULL){return node;} Node *curr = head; while(curr ->next != NULL) { curr= curr->next; } curr->next = node; return head; }
Node *List_insertFront(Node *head, int value) { return Node_create(value, head); }
void List_print(Node *head); { while (head != NULL) { printf("%d", head->value); head = head->next; } }
void List_destroy(Node *head); { while (head != NULL) { Node *tmp = head; head = head->next; Node_destroy(tmp); } }
int main(int argc, char *argv[]) { int i; Node *head = NULL; for (i=0;i<10;i++) { head = List_insertFront(head, i); } List_print(head); printf("value = %d", List_search(head,8)->value); List_destroy(head);
return EXIT_SUCCESS; }