node *segregate(node *head)
{
        node *even,*odd,*even1,*odd1;
        even=odd=NULL;
        while(head)
        {
                if((head->data)%2)      
                {
                        if(!odd)                
                        {
                                odd = head;
                                odd1 = odd;
                        }
                        else
                        {
                                odd1->next = head;
                                odd1 = odd1->next;
                        }
                }
                else
                {
                        if(!even)
                        {
                                even = head;
                                even1 = even;
                        }
                        else
                        {
                                even1->next = head;
                                even1 = even1->next;
                        }
                }
                head=head->next;
        }
        odd1->next=NULL;
        even1->next = odd;
        return (even);
}

On 6/29/11, Nishant Mittal <mittal.nishan...@gmail.com> wrote:
> segregate even and odd nodes in a singly linked list.Order of even and
> odd numbers must be same...
> e.g:-
> i/p list is 4->1->3->6->12->8->7->NULL
> o/p list  4->6->12->8->1->3->7->NULL
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=100000655377926 *

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to