Skip to content

Instantly share code, notes, and snippets.

@devansh42
Created July 29, 2019 19:40
Show Gist options
  • Save devansh42/f04d49521d0183151c313156382f1595 to your computer and use it in GitHub Desktop.
Save devansh42/f04d49521d0183151c313156382f1595 to your computer and use it in GitHub Desktop.
void push_list(LinkedList* list, int value){
Node* n;
n=(Node*)malloc(sizeof(Node)); //intializing new node
n->value=value; //setting value of new node
if(!list->tail){
//It means we are pushing our first node, so intially header and tail node will be same
list->head=n;
list->tail=n;
}
//As tail points to the last element of the list, we will set new node as next element of tail element
list->tail->next=n;
list->tail=n; //As from the above statement n is our new tail, we set new node as tail of list
list->length++; // Increasing length of list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment