Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume the following declarations for a linked list of integers. class LinkedList { Node * head; public: LinkedList ( ) { head = NULL; }

Assume the following declarations for a linked list of integers.
class LinkedList {
Node* head;
public:
LinkedList(){
head = NULL;
}
void insert(int d){
Node* temp = new Node;
temp->data = d;
temp->next = head;
head = temp;
}
int getSum(){...}
};
Write the member function getSum() that returns the sum of all integers in the linked list.
Thus the following code will print 6:
LinkedList list;
list.insert(1);
list.insert(2);
list.insert(3);
cout << list.getSum(); //prints 6

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

What is Centrifugation?

Answered: 1 week ago

Question

To find integral of ?a 2 - x 2

Answered: 1 week ago

Question

To find integral of e 3x sin4x

Answered: 1 week ago

Question

To find the integral of 3x/(x - 1)(x - 2)(x - 3)

Answered: 1 week ago

Question

What are Fatty acids?

Answered: 1 week ago