Given a singly linked list and the task is to find middle of linked list.
Input : 1->2->3->4->5 Output : 3 Input : 1->2->3->4->5->6 Output : 4
We have already discussed Iterative Solution. In this post iterative solution is discussed. Count total number of nodes in the list in recursive manner and do half of this, suppose this value is n. Then rolling back through recursion decrement n by one for each call. Return the node where n is zero.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Practice questions for Linked List and Recursion
- Write a function that counts the number of times a given int occurs in a Linked List
- Flattening a Linked List
- Top 20 Linked List Interview Question
- Count pairs in a binary tree whose sum is equal to a given value x
- Mu Sigma Interview On Campus
- Bank Of America (BA Continuum India Pvt. Ltd.) Campus Recruitment
- Bubble Sort On Doubly Linked List
- Reverse nodes of a linked list without affecting the special characters
- Applications of linked list data structure