Question: Complete the following functions in C++ in relation to circular linked list. -int count(node * head) Iteratively compute and return the number of nodes in
Complete the following functions in C++ in relation to circular linked list.
-int count(node * head) Iteratively compute and return the number of nodes in the circular linked list.
-int countR(node * head) Recursively compute and return the number of nodes in the circular linked list.
-int sum(node * head) Iteratively compute and return the sum of the ints contained in the circular linked list.
-int sumR(node * head) Recursively compute and return the sum of the ints contained in the circular linked list.
Starter Code (Assume all you have to do is complete the functions above and all other resources and code is provided.):
int main()
{
node* head{nullptr};
/* Builds a circular linked list with a random number of nodes
*containing randomly-chosen numbers.
*/
build(head);
display(head);
// PUT YOUR CODE HERE to call the functions assigned,
// and print out the results. For example,
//
// cout << "iterative sum: " << sum(head) << endl;
//
// The code for your functions should be in clist.cpp.
// When called the 2nd time, this also prints the total
// of the numbers in the nodes.
display(head);
int nNodesFreed{0};
node* n{head};
node* temp;
while( n != head || ! nNodesFreed) {
temp = n->next;
delete n;
n = temp;
nNodesFreed++;
}
cout << "# nodes freed: " << nNodesFreed << endl;
//destroy(head);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
