Linkedlist code isnt working getting undesired output

not getting desired output

Hi @kul_boii
Problem is in your length function where you are missing ! in while loop condition and you are not moving head forward.

It should be like this :

int length(node *head)
{
int len = 0;
while (head->next != NULL)
{
len++;
head=head->next;
}
return len;
}

1 Like