You are viewing a single comment's thread. Return to all comments →
Solution in C:
Node* InsertNth(Node *head, int data, int position) { int count=0; Node *new_node; Node *n_ptr; n_ptr = head; new_node = (struct Node*) malloc(sizeof(struct Node)); new_node->data = data; if(position==0){ new_node->next = head; return new_node; } else{ while(count!=position-1){ n_ptr = n_ptr->next; count++; } new_node->next = n_ptr->next; n_ptr->next = new_node; return head; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
Solution in C: