You are viewing a single comment's thread. Return to all comments →
Here is my Solution in Java :
public static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode llist, int data, int position) { SinglyLinkedListNode currentNode = llist; int index = 0; while(currentNode != null) { if (index == position) { SinglyLinkedListNode tempNode = new SinglyLinkedListNode(currentNode.data); tempNode.next = currentNode.next; currentNode.data = data; currentNode.next = tempNode; } currentNode = currentNode.next; index++; } return llist; }
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
Here is my Solution in Java :