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.
Agreed in fact something like what you are sayign is the most elegant solution, I thought mine was :/
Noden=newNode();n.data=data;Nodecur=head;Nodeprev=null;inti=0;while(i<position){prev=cur;cur=cur.next;i++;// will crash if input head = null and pos > 0 // we assume no such inputs}n.next=cur;if(prev!=null){prev.next=n;returnhead;}returnn;
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 →
Agreed in fact something like what you are sayign is the most elegant solution, I thought mine was :/