Search This Blog

Sunday, September 21, 2014

Find middle node of given singly linked list

1:  list_t * middle_node()  
2:  {  
3:    list_t *slow = start;  
4:    list_t *fast = start;  
5:    while(fast != NULL && fast->next != NULL)  
6:    {  
7:      slow = slow->next;  
8:      fast = fast->next->next;  
9:    }  
10:    printf("Middle Node is : %d\n",slow->data);  
11:    return slow;  
12:  }  

No comments:

Post a Comment