CS120
Lab #12
Due at the end of lab.
Chapter 8 in the course textbook contains a great discussion of implementing a linked list.
You should read that chapter before starting this lab and refer to it while you are working on this lab.
For this lab you are to build a linked list.
Each node (or item) in the list should contain a single data value of type double.
This value must be private.
You may name this value whatever you want, but in this document it will be referred to as xxx.
Each node in the linked list should also contain the following methods:
- A getNext() method that returns the address of the next node in the list.
This method should take no arguments.
- A setNext() method that sets the next item in the list to be the address that is passed in as an argument. This method should not return a value.
- A getValue() method that retrieves the value of the node's xxx field and returns it to the caller. This method should take no arguments.
- A setValue() method that sets the value of the node's xxx field to the value of type double passed in as an argument. This method should not return a value.
- A incValue() method that increments the value of this node's xxx field by 1. This method takes no arguments. This method should return the old value of the xxx field (the value *before* the increment).
- A size() method that that determines the count of the number of nodes in the list including this node. This method takes no arguments and should return one value of type int indicating the computed result.
- A largest() method that that determines the largest of all values in the list including this node. This method takes no arguments and should return one value of type double indicating the computed result.
- A smallest() method that that determines the smallest of all values in the list including this node. This method takes no arguments and should return one value of type double indicating the computed result.
- A average() method that that determines the average of all values in the list including this node. This method takes no arguments and should return one value of type double indicating the computed result.
- A print() method that will print the values in the list including this node. This method should take no arguments and return no value.
- A clear() method that will remove all nodes from the list and use the delete operator to relinquish memory used by the nodes. This method should take no arguments and return no value.
You will also need to make a main() function that creates a list of nodes and exercises functionality specified above in order to test your program.
Be sure to thoroughly test your code.
Provide a printout demonstrating all behavior specified above.
It is recommended that
In demonstrating that your code works, you should use a list containing at least 8 nodes.
Turn in: A copy of your code and sample output demonstrating that your linked list behaves as specified.
Place your sample output in a file named Lab12output.txt Submit a copy of your code and your Lab12output.txt file to Canvas.