You are viewing a single comment's thread. Return to all comments →
Java 8 Code
public static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode llist, int data, int position) { // Write your code here
if(position > 1) { insertNodeAtPosition(llist.next, data, position-1); } else if(position == 1) { if(llist.next == null) { llist = new SinglyLinkedListNode(data); } else { SinglyLinkedListNode newNode = new SinglyLinkedListNode(data); newNode.next = llist.next; llist.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 →
Java 8 Code
public static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode llist, int data, int position) { // Write your code here