Singly Linked List
Video Lecture
copy over all the files provided for you
the files are in the usual place
For this assignment you will create a Template Singly Linked List
we will be adding to it in the next lab as well
Run the Example Program to see the Singly Linked List in action
your job is to duplicate the action of the example
There is also a visual demonstration of a linked list here
you will use this as the model for all your node based template containers, ie the next few homework assignments
for tonight's lab you Will complete the Constructor,Insert and ToString functions
YOUR ToString MUST WORK WITH THE WEBPAGE
viewlist
test files have been provided for you make sure you program output matches the examples
when you redirect in ALL of the test files
since we do not have a destructor to clean up the nodes we created we will have a memory leak
you can see this when you run
valgrind --leak-check=full ./runme_int < testfiles/testinput2_int
==7665== LEAK SUMMARY:
==7665== definitely lost: 16 bytes in 1 blocks
==7665== indirectly lost: 112 bytes in 7 blocks
==7665== possibly lost: 0 bytes in 0 blocks
File: SLinkedList.h
#pragma once
#include "cmpslib19.h"
#include "easylogging++.h"
template <class T>
class SLinkedList
{
/*
We need a node that is templated to store the same type as our
Linked List. The easiest way to do this is make it an "Inner" class
It contains an element of the template type
and a pointer to the next node in the list.
*/
class SListNode
{
public:
T data;
SListNode *next;
// when you create a node you can pass in the value it should store
SListNode(T val) {data = val; next = nullptr;}
};
SListNode * head;
public:
SLinkedList()
{
// set head to the nullptr
}
bool Insert(T val)
{
// insert a new node to store val
// at the head of the list
// create a new node to store the value to be added
// set the next pointer of the new node to point to the current first node in the list
// make this node the new front by setting the head pointer to it
}
string ToString()
{
// return a text representation of the stack
// IT MUST WORK WITH THE WEBPAGE
// run the example and use the ouput of the ToString function as a guide
}
}; // end SLinkedList