where i am going wrong
Oddeven linkedlist https://ide.codingblocks.com/s/177549
Hey @ashutoshu
You need to correct your code at a couple of places:
In the main function:
int main()
{
node *head=NULL;
int n;
cin>>n;
while(n–)
{
int data;
cin>>data;
inserttail(head,data);
head=oddeven(head);
print(head);
}
return 0;
}
You need to write the following statements out of the while loop:
head=oddeven(head);
print(head);
-Also, You need to handle a case where after running the oddeven function, the oddstart will be NULL, then you can’t write oddend->next = evenstart, coz that’ll give segmentation error.
So you need to handle it in the oddeven function like:
The last lines of your function after the while loop should be:
evenend->next=NULL;
if(!oddstart) return evenstart;
oddend->next=evenstart;
return oddstart;
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.