Segregate even and odd psoitioned nodes in a linked list
Eg:
2->3->1->9->7->5
The output should be two separate lists
2->1->7
3->9->5
*My code is:*
void segregate(node* head)
{
int i=1;
node* sec=head->next;
node *odd=head,*even=head->next;
while(even)
{
if(i%2)
{
odd->next=even->next;
even->next=NULL;
odd=odd->next;
if(!odd->next) break;
}
else
{
even->next=odd->next;
odd->next=NULL;
even=even->next;
if(!even->next) break;
}
i++;
}
}
Pls correct me if i'm wrong or suggest me a better approach
Regards,
KARTHIKEYAN.V.B
PSGTECH
CBE
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.