Adding a Node in Singly Linked List
1) at the Beginning
2) at the end
3) at a specific location
Inserting a Node at the beginning of the singly Linked List
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | NODE *newNodeF( int key) { NODE *temp = (NODE *) malloc ( sizeof (NODE)); temp->data = key; temp->next = NULL; return temp; } void insertAtBeg() { struct node *temp=head; int data; if (temp==NULL){ head=newnode; return ; } printf (“Enter data to add at begining\t”); scanf (“%d”,&data); struct node *newnode=newNode(data); newnode->next=temp; head=newnode; } |
also see
C Programming language |
Go Programming language |
Linked List | Array |
Stack | Queue |
Puzzle | Reasoning |
Aptitude | HTML |