Try to do it asap give output screenshots
Complete the code, where it says "TO DO"
code:
#ifndef __SLLIST_H__
#define __SLLIST_H__
#include "Node.h"
#include
// size should not be negative
typedef unsigned long size_t;
namespace ds {
template class TestDriver; // for autograding; please ignore
/** Singly linked list. */
template
class SLList {
friend class TestDriver; // for autograding; please ignore
private:
/** Pointer pointing to the sentinel node. */
Node *sentinel;
/** Stores the current size of the list. */
size_t count;
public:
/** Construct a new SLList object. */
SLList() {
sentinel = new Node(ItemType(), nullptr);
count = 0;
}
/** Add x at the beginning of the list. */
void addFirst(ItemType x) {
count += 1;
sentinel->next = new Node(x, sentinel->next);
}
/** Return the first element. */
ItemType &getFirst() const {
assert(sentinel->next != nullptr);
return sentinel->next->item;
}
/** Return the number of elements in list. */
size_t size() const { return count; }
/** Append the list with x. */
void addLast(ItemType x) {
count += 1;
Node *p = sentinel;
while (p->next != nullptr) {
p = p->next;
}
p->next = new Node(x, nullptr);
}
SLList(const SLList &other);
~SLList();
ItemType &get(int i) const;
ItemType removeFirst();
ItemType removeLast();
};
/** Copy constructor. */
template
SLList::SLList(const SLList &other) {
// TODO: create a list that is identical to `other`
}
/** Destroy the SLList object. */
template
SLList::~SLList() {
// TODO:
}
/** Return the i-th item in list. */
template
ItemType &SLList::get(int i) const {
// TODO:
}
/** Delete and return the first item of the list. */
template
ItemType SLList::removeFirst() {
// TODO:
}
/** Delete and return the last item of the list. */
template
ItemType SLList::removeLast() {
// TODO:
}
} // namespace ds
#endif // __SLLIST_H__