append to linked list code example
Example 1: append method linked list python
def append(self,item):
current = self.head
if current:
while current.getNext() != None:
current = current.getNext()
current.setNext(Node(item))
else:
self.head = Node(item)
Example 2: append to list in c
void Append(Node *head, Node node){
Node tmp = *head;
if(*head == NULL) {
*head = node;
return;
}
while(tmp->next != NULL){
tmp = tmp->next;
}
tmp->next = node;
return;
}