Question: Consider the circular linked list data structure. It is similar to the standard linked list data structure we studied, except that the last node's next

Consider the circular linked list data structure. It is similar to the standard linked list data structure we studied, except that the last node's next pointer points back
to the first node instead of being nullptr.
Write a C++ function countList that returns how many elements there are in a circular list. For example, for the list pictured above, your function should return
It must take one parameter: a pointer the first node in the list head. You may assume that the parameter passed in points to a valid circular list with at least 2
elements. You may use the Node class defined below for your nodes, or define your own.
class Node {
public:
int data;
Node* next;
};
Your function must have the following signature:
int countList (Node* head)
You do not need to demonstrate calling this function from main().
 Consider the circular linked list data structure. It is similar to

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!