I started with basic linkedlist operations.
This is a program to insert a new node at the beginning or a specific position in linkedlist.
I understand the first picture has the case where if linked list is empty insert return new node.
- If invalid position for insertion, return head.
- Last if else block, if position is at the beginning insert new node at the beginning, point next to head and return new node.
- I understand what else block is doing, inserting at a specific position.
Question (I know it is dumb): why are we returning headNode
at the end if we had returned a node in every case/block mentioned above?
Should it not be returned inside the last else block but not outside?