CMPS-2020 Programming II: Data Structures and Algorithms
Lab-11

Components:

Lab Details
We will start by writing a portion of the lab together.
Follow along.

Name your program...
/2020/b/lab11.cpp


When we have completed the together programming...

Go to chapter-17 in our Gaddis textbook.
Do programming challenges 1 through 7.
Apply the challenges to the program we wrote.

1. Your Own Linked List

Design your own linked list class to hold a series of integers. The class
should have member functions for appending, inserting, and deleting nodes.
Don't forget to add a destructor that destroys the list. Demonstrate the class
with a driver program.

2. List Print

Modify the linked list class you created in Programming Challenge 1 to add a
print member function. The function should display all the values in the linked
list. Test the class by starting with an empty list, adding some elements, and
then printing the resulting list out.

3. List Copy Constructor

Modify your linked list class of Programming Challenges 1 and 2 to add a copy
constructor. Test your class by making a list, making a copy of the list, and
then displaying the values in the copy.

4. List Reverse

Modify the linked list class you created in the previous programming challenges
by adding a member function named reverse that rearranges the nodes in the list
so that their order is reversed. Demonstrate the function in your lab11 program.

5. List Search

Modify the linked list class you created in the previous programming challenges
to include a member function named search that returns the position of a
specific value in the linked list. The first node in the list is at position 0,
the second node is at position 1, and so on. If x is not found on the list, the
search should return -1. Test this function in your lab11 program.

6. Member Insertion by Position

Modify the list class you created in the previous programming challenges by
adding a member function for inserting a new item at a specified position. A
position of 0 means that the value will become the first item on the list, a
position of 1 means that the value will become the second item on the list,
and so on. A position equal to or greater than the length of the list means
that the value is placed at the end of the list.

7. Member Removal by Position

Modify the list class you created in the previous programming challenges by
adding a member function for deleting a node at a specified position. A value
of 0 for the position means that the first node in the list (the current head)
is deleted. The function does nothing if the specified position is greater than
or equal to the length of the list.

8. Member Insertion by Order

Modify the list class you created in the previous programming challenges by
adding a member function for inserting a new node at whatever position that
will keep the list in ascending sequence.

8. Overload the [] operator Write a member function that let's your program use the [] operator to access nodes in your linked list. A value of [0] will refer to the first node in the list. Demonstrate its use.
A main function for testing insert/display/remove is below. int main() { Llist a; cout << "inserting 25, 35, 45 into a\n"; a.insert(25); a.insert(35); a.insert(45); a.display(); cout << "copying b = a\n"; Llist b = a; b.display(); cout << "inserting 55 into a\n"; a.insert(55); a.display(); b.display(); cout << "removing 35 from b\n"; b.remove(35); a.display(); b.display(); cout << endl; return 0; }

Homework
What you don't finish in the lab becomes homework.


Check back here for more homework.


What to turn in...
Your instructor will find your work out on Odin.