Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Monday, October 23, 2017

separate LL in two parts by even odd position


Code:

 Node rearrange(Node head)
    {
        if(head==null)
        return head;
        Node h=head;
          Node t=head.next;
          Node st=t;
          while(t!=null && t.next!=null && head!=null)
          {
              head.next=t.next;
              head=head.next;
              if(head.next==null)
              {
                  t.next=null;
                  break;
              }
              t.next=head.next;
                  t=t.next;
             
          }
         
                  head.next=st;
          return h;
     }

0 Comments:

Post a Comment

Stats