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.
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'
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
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'