Lab 14
Linked structures
Check out the lab using this form
Scenario: In today's lab we will look at how to write the code to reverse a list.
We have provided lots of examples of code in this program called LinkedListEverythingInClass2.cpp.
In lab14_question.cpp, the original program would give the following output.
$ ./lab14
Linked list sample program, Inserting in order.
Enter as many integers > 0 as you would like, followed by -1: 2 9 3 -1
Linked list sample program, Inserting in order.
Enter as many integers > 0 as you would like, followed by -1: 8 3 5 -1
List contains: 9 3 2 8 5 3
List contains: 9 8 5 3 3 2
Ending Linked List program. Exiting ...
The task for today's lab
-----------------------------
1. Modify the function insertNodeInOrder so that the function order numbers in an ascending order.
The modified program would give the following output.
$ ./lab14
Linked list sample program, Inserting in order.
Enter as many integers > 0 as you would like, followed by -1: 2 9 3 -1
Linked list sample program, Inserting in order.
Enter as many integers > 0 as you would like, followed by -1: 8 3 5 -1
List contains: 2 3 9 3 5 8
List contains: 2 3 3 5 8 9
Ending Linked List program. Exiting ...
2&3. Implement a function called void reverseList( Node *&pHead) to reverse a list. Once the program is done, pHead should point to the node that used to be the last list Node in the linked list.