You are viewing a single comment's thread. Return to all comments →
SinglyLinkedListNode* insertNodeAtPosition(SinglyLinkedListNode* llist, int data, int position) { SinglyLinkedListNode* newnode = (SinglyLinkedListNode*)malloc(sizeof(SinglyLinkedListNode)); newnode->data = data; newnode->next = NULL; SinglyLinkedListNode* temp = llist; if(llist == NULL) { llist = newnode; } else { for (int i=1; i<position; i++) { temp = temp->next; } newnode->next = temp->next; temp->next = newnode; } return llist; }
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 →