178k views
1 vote
C++

For your lab, you will implement a template version of a linked list, capable of using any comparable types (types for which the relational operators are defined). You will need to define the following templates:
The Node struct
A recursive function to display the contents of the linked list.
A recursive function to calculate the length of the linked list.
A function to add an element to an already sorted linked list.
A function to delete an element from a sorted linked list.
A function to search for an element in the linked list.
In the main, you will first create a new linked list capable of storing doubles, and populate the linked list with the contents of the numbersUnsorted.txt text file that is provided.
Then, use a menu-driven program to provide the user with the following options:
Display the contents of the linked list
Display the length of the linked list
Add a new element to the linked list in sorted order
Delete an element from the linked list
Search for an element in the linked list
Exit the program
numbersUnsorted.txt:
13.37
42.01
78.25
16.68
43.57
64.00
54.57
10.78
99.99
57.77
80.01
34.82
29.44

User Wade Huang
by
8.4k points

1 Answer

5 votes

Final answer:

This lab involves implementing a linked list template in C++ that can store any comparable type. The main program includes creating the list, populating it with numbers from a text file, and offering menu-driven options to manipulate the list.

Step-by-step explanation:

In this lab, you will be implementing a template version of a linked list in C++. The linked list will be capable of storing any comparable types. You will need to define a Node struct, a recursive function to display the contents of the list, a recursive function to calculate the length of the list, a function to add an element to a sorted list, a function to delete an element from the sorted list, and a function to search for an element in the list.

In the main program, you will create a new linked list that can store doubles. You will populate this list with the contents of a text file called numbersUnsorted.txt. The text file contains a list of numbers. After creating the list, you will provide a menu-driven program that offers various options to the user, such as displaying the contents of the list, calculating the length of the list, adding a new element to the sorted list, deleting an element from the sorted list, searching for an element in the list, and exiting the program.

User PabloRN
by
7.5k points