Given a singly linked list, find the node in the middle.
Click for Solution
  • puneeth node cur,cur1;
    cur=first;
    cur1=first;
    while(cur1!=null)
    {
    cur=cur->link;
    cur1=cur1->link;
    cur1=cur1->link;
    }
    printf("middle node is %d",cur->info);

  • puneeth 1. take two references to first node like,
    cur=first and cur1=first.
    2. wen cur is traversed once ,let cur1 to traverse twice so that when
    cur1 is at the end of list cur will be pointing to middle of the list.

[Insert Code]