Question: Write a C++ program to display middle element of a linked list in one pass? Hint: Create two pointers slow and fast. Move the fast
Write a C++ program to display middle element of a linked list in one pass?
Hint: Create two pointers slow and fast.
Move the fast pointer two nodes at a time & slow pointer one node at a time.
Check when the link part of the fast pointer becomes NULL (odd number of nodes) or the fast pointer becomes NULL (even number of nodes), at that point slow pointer points to the middle element.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
