Lab 13: Linked List
In this lab, you will write a program that manipulates Linked List.
The execution of the finished program should look what is shown below (User input is shown in bold).
Author: Hong Wang
Lab: Thursday 2pm
Program: Lab 13: Linked List
Available commands:
insert <CHARACTER> <FREQUENCY>
undo
exit
Current linked list:
$ insert a 123
Current linked list:
[a/123]
$ insert b 2345
Current linked list:
[b/2345] -> [a/123]
$ insert x 777
Current linked list:
[x/777] -> [b/2345] -> [a/123]
$ undo
Current linked list:
[b/2345] -> [a/123]
$ undo
Current linked list:
[a/123]
$ insert x 999
Current linked list:
[x/999] -> [a/123]
$ exit
The skeleton code is provided here: Lab13.cpp, you need to implement three functions.
DO NOT change any code within 'main' function.
Stage 1 (1 point):
Implement function void displayList(Node* pHead), which display the entries in the list.
Example:
[x/777] -> [b/2345] -> [a/123]
Stage 2 (1 point):
Implement function Node* addNode(Node* pHead, char c, int count), which
Creates a new node using given values
Inserts the new node at the beginning of linked list
Returns the new head pointer
Notice that since we are creating the linked list dynamically, we need to use dynamic memory allocation (either 'new' or 'malloc')
Stage 3 (Extra Credit, 1 point):
Implement function Node* deleteMostRecentEntry(Node* pHead), which
Deletes the most recent added node
Frees the memory of that node!
Returns the new head pointer
References:
Submission:
You should work with a partner for a grade. Only one submission per group is necessary, but be sure to include your name if you work alone, or both people's names if you worked with a partner.
You should submit the lab to the Blackboard at the end of the lab session, by 50 minutes after the hour.