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
Get step-by-step solutions from verified subject matter experts
