Question
Design and write a class that implements an ordered list type, using a linked list as described in class, and a program that exercises and
Design and write a class that implements an ordered list type, using a linked list as described in class, and a program that exercises and tests the class's list implementation. The elements of the class's lists will be integers, but it should be easy to change this type.
The class will implement the following operations on ordered linked lists of its element type:
Initialize a list to be empty (the default constructor).
Re-initialize an existing list to be empty.
Insert a value into a list, in the appropriate position. If the value is already present, the list is unchanged.
Remove a value from a list. If the value is not present, the list is unchanged.
Return the length of a list.
Report whether or not a particular value is present in a list.
Return the value of the kth element of a list.
Write out the values in a list, in order, to an output stream.
The exercising program will be menu-driven and interactive. The program will read and respond to commands that the user enters. It will manipulate a list of integers provided by the class.
INPUT
The program will read commands to manipulate its list. These commands will consist of a letter followed perhaps by one integer. For example, the command "i 25" might tell the program to insert the value 25 into the list.
OUTPUT
The program will write to the terminal instructions and a menu of commands, and it will prompt for the user's input.
ERRORS
The program may assume that the input the user provides is correct; except that it will report if a position is beyond the end of a list (See the example below). Otherwise, it need not detect any errors.
EXAMPLE
A run of the program might look something like this:
This program responds to commands the user enters to manipulate an ordered list of integers, which is initially empty. In the following commands, v is any integer, and p is a position in the list. e -- Re-initialize the list to be empty. i v -- Insert the value v into the list. r v -- Remove the value v from the list. l -- Report the length of the list. p v-- Is the value v present in the list? k p -- Report the pth value of the list. w -- Write out the list. h -- See this menu. q -- Quit. --> i 27 --> i 42 --> i 15 --> i 33 --> i 14 --> w List: < 14, 15, 27, 33, 42 > --> r 33 --> w List: < 14, 15, 27, 42 > --> p 22 The value 22 is NOT present in the list. --> p 42 The value 42 is present in the list. --> k 3 The 3th element of the list is 27. --> k 9 The list does not contain 9 values. --> q
This example does not illustrate everything the program might do; show tests of all its features.
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