CMPS-2020 - Programming II - Data structures and algorithms
This is part of your midterm exam.
Individual work by each student.
-------------------------------------------------------------
Your work will be done on Odin in your 2020/c/ folder.
Start with the program at:
/home/fac/gordon/public_html/2020/c/circular.cpp
Assignment:
-----------
1. Modify this doubly-linked list to a circular linked-list.
---------------------------------------------------------
The last node's next pointer will point to the head node.
The head node's previous pointer will point to the last node.
2. Modify the following functions:
-------------------------------
addNode - add a new head node
display - display the linked-list data
3. Add the following function:
---------------------------
displayReverse - display the linked-list data in reverse
Rules:
------
1. Do not change the private data section of the LinkedList class.
2. You may use a break statement in your display functions.
Hints:
------
When displaying nodes forward, display until the current node's next pointer
points to the head node.
When displaying nodes in reverse, start at the last node, then display until
the current node is the head node.
How to find the last node? The head node's previous pointer points there.
Testing:
--------
Your instructor will test your program with a main function
something like this:
int main() {
LinkedList l;
l.addNode(1);
l.display();
l.displayReverse();
l.addNode(2);
l.display();
l.displayReverse();
l.addNode(3);
l.display();
l.displayReverse();
l.addNode(4);
l.display();
l.displayReverse();
cout << endl;
return 0;
}
The output will be:
1
1
2 1
1 2
3 2 1
1 2 3
4 3 2 1
1 2 3 4
=========================================================
The following file will be collected Wednesday at 8:00pm.
2020/c/circular.cpp