Question
Write a c++ function that takes a linked list of ints as a parameter and returns the weight of the list where the weight is
Write a c++ function that takes a linked list of ints as a parameter and returns the weight of the list where the weight is equal to the sum of the depth*data for each node in the list. The linked list class has functions .getSize() which returns the number of nodes(ints) in the list, .getFront() which returns the front integer, and .deleteFront() which deletes the front node and makes the next node the front.
*NOTE: not using a built in class, linked list class built in header file
Example list
Depth | Data |
1 | 2 |
2 | 4 |
3 | 3 |
4 | 1 |
Weight = (1*2) + (2*4) + (3*3) + (4*1) = 23
int calculateWeight(list d) {
return weight;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started