You are viewing a single comment's thread. Return to all comments →
public static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode llist, int data, int position) { int currentPosition = 0; SinglyLinkedListNode currentLList = llist; while(currentLList.next != null && currentPosition<position-1){ currentPosition++; currentLList = currentLList.next; } SinglyLinkedListNode result = new SinglyLinkedListNode(data); result.next = currentLList.next; currentLList.next = result; 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 →