Question: answer in c++ and answer with the 2 methods a. Given a singly linked list, write a function that find the middle of the linked

answer in c++
and answer with the 2 methods
a. Given a singly linked list, write a function that find the middle of the linked list. For example, if given linked list is 1->2->3->4->5 then output should be 3. If there are even nodes, then there would be two middle nodes, we need to print second middle element. For example, if given linked list is 1->2-> 3->4->5-> then output should be 4. Method 1: 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. Method 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
