You are viewing a single comment's thread. Return to all comments →
Node* InsertNth(Node *head, int data, int position) { struct Node *i,newn; int count=0; newn=(struct Node)malloc(sizeof(struct Node)); newn->data=data; if(!head) { newn->next=NULL; head=newn;
} else if(position==0){ newn->next=head; head=newn; } else{ i=head; while(i->next!=NULL&&count<(position-1)){ i=i->next; count++; } newn->next=i->next; i->next=newn;
} 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 →
Node* InsertNth(Node *head, int data, int position) { struct Node *i,newn; int count=0; newn=(struct Node)malloc(sizeof(struct Node)); newn->data=data; if(!head) { newn->next=NULL; head=newn;
} return head; }