Doubly Linked List
there is an interactive demonstration of a double linked list HERE
Video
copy over all the files provided for you
the files are in the usual place
then add the complete and functional main.cpp and , SLinkedList.h from the Singly Linked List homework
For this assignment you will create a Template Doubly Linked List
Run the Example Program to see the Doubly Linked List in action
your job is to duplicate the action of the example
use your Singly Linked List as the starting point
RENAME YOUR FILE to DLinkedList.h
using search and replace in vi will help speed up the operation considerably
Esc : (enter command mode)
%s/SLinkedList/DLinkedList/g
this will replace all instances of SLinkedList with DLinkedList in the file
20,25s/SLinkedList/DLinkedList/g
this will replace all instances of SLinkedList with DLinkedList in lines 20 to 25 just in case you were currios how the search and replace works
for tonight's lab you need to verify that you have a fully functional Constructor, Destructor, Insert, Insert After and ToString functions
1
add a second node pointer (previous) to your DListNode inner class
set the previous pointer to the nullptr in the DListNode constructor
2
and a second node pointer (tail) to your DLinkedList class
set it to the nullpointer in the DLinkedList constructor
3
add the code to display the previous pointer and the tail to your ToString function
4
copy your ToSTring function and rename it ToStringBackwards
just change the logic to make it traverse back to front
DLinkedList * temp = tail;
while (temp->previous != nullptr)
{
print values
temp = temp->previous;
}
5
modify your Insert and InsertAfter functions to account for the additional previous pointers
your destructor should work without modifications
Your other functions may not work properly until you update them to include the logic to deal with the additional pointer in the node and the tail pointer.
only very minor changes to your main should be needed
you will need to test by adding values and printing it out, make sure that both the prev and next pointers are set and that they link to the correct nodes
a good test is the viewlist page
test that your destructor cleans up any created nodes.. (your previous SLinkedList destructor should work)
add some logic to the ToString function so it had the value of the next pointer for each node (see example output)
THE EXAMPLE HAS LOTS OF LOGGING , make sure your logging matches the example to help guide you
the logging says line by line what the function is doing, use them as instructions on what you need to change
you can use a separate terminal window to monitor a logfile or anyfile that chages in real time with
tail -f filename
I highly suggest you have a separate terminal to monitor the example logfile
make sure to test by inserting after a value that does not exist
and insert after the last value
YOUR ToString MUST WORK WITH THE WEBSITE
http://cs.csubak.edu/~msarr/cmps2020/viewlist.php
and show up as double linked list