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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!