Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago