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.
Insert a node at a specific position in a linked list
Insert a node at a specific position in a linked list
Sort by
recency
|
34 Discussions
|
Please Login in order to post a comment
Python 3
However I look at this, the 'position 0' case seems special as you return a different 'head'. The simplest option I could see was to treat it as a separate case.
I quite like the proposed naming and structure here of 'next_index' being the count, starting from 1, and running through the llist until you find the right point to do the insert... although maybe 'node_count' or something would be more technically correct than 'index'
c++
SinglyLinkedListNode* insertNodeAtPosition(SinglyLinkedListNode* llist, int data, int position) { SinglyLinkedListNode* newNode = new SinglyLinkedListNode(data);
}
in java 8 getting error in main methode and declearing staitc how to resolve that