Singly Linked List
copy over all the examples and testfiles provided for you
as well as your SLinkedList.h, Makefile and main
from the linked list labs
there is aditional information and videos in the 2 related labs
YOU MUST:
1. make it a template class
2. put all your function bodies inside the class
3. make your ListNode an inner class
4. include testfiles where you fully test your classes .. for all 3 datatypes
5. your code should have no compilation warnings
6. make your code such that no combination of function calls will result in a seg fault, throw exceptions when needed
7. do the standard file logging
Start with the Single linked list lab and add the functions for
Run the Example Program to see the Singly Linked List in action
your job is to duplicate the action of the example
you will need
// a destructor that deletes all the nodes in the container
~SLinkedList()
// insert val into the list AFTER the first occurrence of val2
bool InsertAfter(T val ,T val2);
// delete the first node found with the value val
bool Delete(T val);
flowchart
// delete the last value from the list
bool DeleteEnd();
// does the List contain the value val? true or false
bool Contains(T val);
// is the container empty
bool empty();
// return a reference to the front element
T & Front();
// return a reference to the back element
T & Back();
Linked List Menu
==================================================
i Insert a value into the list
a Insert a value After a value
d Delete a value from the list (1st from front)
e Delete from the end (last value)
c Does the list contain a specific value
p Print the value returned by ToString()
f Print the value returned by Front()
b Print the value returned by Back()
m Show this menu
x Exit
==================================================
Enter selection:
MAKE sure you output matches the examples when you redirect in the testfiles
MAKE sure your ToString output can be used on the viewlist page
viewlist
in order to test you are going to want to
add values,
delete values,
add at the front, middle and back
delete from the front, middle and back
print out the ToString output and make sure
the head always has the address of the first node
the next pointers of every node are set correctly
if your ToString output correctly works with the viewlist app it will help
identify problems
WHEN IN DOUBT open up two terminals and run the example and yours side by side
since YOU SHOULD NOW have a destructor to clean up the nodes
there should be no memory leaks
you can see this when you run
valgrind --leak-check=full ./runme_int < testfiles/testinput2_int
==7604== LEAK SUMMARY:
==7604== definitely lost: 0 bytes in 0 blocks
==7604== indirectly lost: 0 bytes in 0 blocks
==7604== possibly lost: 0 bytes in 0 blocks
Helpful hints:
get a working insert, add values in make sure it works
do the delete, fill the list with 5 values delete the middle value and print it
, fill the list with 5 values delete the first value and print it
, fill the list with 5 values delete the last value and print it
now work on the insert after make sure it can insert at the middle and end
make sure you test front, back and delete on an empty list
maybe put a cout statement( remove when done ) or look at the logs to make sure you are calling delete as many times as you have values in the list and use valgrind to test it as well