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
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 |