Do we count nodes of link list as 0,1,2
or 1,2,3 etc because i am confused to set the counter for nodes.
INsertion in mid in link list
in both the case middle will not change
either you count form 0 or 1
and when you do questions you can get an idea from sample input whether they start from 0 or 1.
in this question of insertion in mid of link list
use 2 pointer approach fast and slow
node* slow=head;
node*fast=head->next;
while(fast->next&&fast->next->next){
fast=fast->next->next;
slow=slow->next;
}
after this your slow is just behind mid element
now you can insert at mid very easly
i hope this help
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.