We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
With java 15, solution for inserting new node at any position
publicstaticSinglyLinkedListNodeinsertNodeAtPosition(SinglyLinkedListNodellist,intdata,intposition){// Write your code hereSinglyLinkedListNodecurr=llist;intcount=1;while(curr!=null){if(count==position){SinglyLinkedListNodenext_node=newSinglyLinkedListNode(data);SinglyLinkedListNodecurr_node=curr.next;curr.next=next_node;next_node.next=curr_node;}
curr = curr.next;
count++;
}
return llist;
}
Cookie support is required to access HackerRank
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 →
With java 15, solution for inserting new node at any position