2 - Linked List Implementation I - 2101702130 - Andrean

Pertemuan ke - 2 27-02-2018 Linked List: - Single Linked List Simplest linked list. Define a node structure : struct tnode { int value; struct tnode *next; }*head=NULL,*tail=NULL,*curr; head is the pointer for the first element in our linked list. tail is the pointer for the last element in our linked list. Insert Head: struct tnode *node = (struct tnode*) malloc(sizeof(struct tnode)); //make a new node node->value = x; node->next = head; head = node; Tail: struct tnode *node = (struct tnode*) malloc(sizeof(struct tnode)); //make a new node node->value = x; node->next = NULL; tail->next = node; tail = node; Delete // if x is in head node if ( head->value == x ) { head = head->next; free(curr); } // if x is in tail node else if(tail->value == x){ while(curr->next!=tail) curr = curr->next; ...