Hey I'm having trouble inserting a node in a nth position into a double linked list. My for loop is
giving me an exception handler error and I can't link the node after the new node is inserted back to the new node.
Here is my code,
First of all, post corrected code (with pos used where it's required) and better variable names.
But while I'm here:
- There's no point passing an int by const reference. That should only be done for class types, not built-in types like int, double, etc.
- line 4 and 5 shouldn't be needed if you have a constructor (which appears to be the case from line 3)
- temp3 is v prob unnecessary
- when you add a new node at the head, you're not setting up prev
- what happens when you try to insert after a node which is at an index past the end of the list?