Given a singly linked list, find middle of the linked list. Given a singly linked list, find middle of the linked list. For example, if given linked list is 1->2->3->4->5 then output should be 3.
Traverse the whole linked list and count the no. of nodes. Now traverse the list again till count/2 and return the node at count/2.
Traverse linked list using two pointers. Move one pointer by one and other pointer by two. When the fast pointer reaches end slow pointer will reach middle of the linked list.
The middle element is: 2
Initialized the temp variable as head
Initialized count to Zero
Take loop till head will become Null(i.e end of the list) and increment the temp node when count is odd only, in this way temp will traverse till mid element and head will traverse all linked list. Print the data of temp.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Insert N elements in a Linked List one after other at middle position
- Find the middle of a given linked list in C and Java
- Find middle of singly linked list Recursively
- Find kth node from Middle towards Head of a Linked List
- Traverse Linked List from middle to left-right order using recursion
- Given a linked list of line segments, remove middle points
- Delete middle of linked list
- Insert node into the middle of the linked list
- Make middle node head in a linked list
- Iterative approach for removing middle points in a linked list of line segements
- Find the second last node of a linked list in single traversal
- Circular Linked List | Set 2 (Traversal)
- Recursive insertion and traversal linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Check if a linked list is Circular Linked List
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Convert Singly Linked List to XOR Linked List
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.