I need to implement a Template Linked List in C++ , and I'm asked to use three Fixed file(which is cannot changed):
ContainerIfc.h
class BADINDEX {};
template <class T>
class ContainerIfc {
public:
virtual ContainerIfc <T>& pushFront(T) =0;
virtual ContainerIfc <T>& pushBack(T) =0;
virtual ContainerIfc <T>& popFront(T&) =0; // throws BADINDEX
virtual ContainerIfc <T>& popBack(T&) =0; // throws BADINDEX
virtual int getSize() =0;
virtual bool isEmpty() =0;
virtual T front() =0; // throws BADINDEX
virtual T back() =0; // throws BADINDEX
virtual T& operator [](int) =0; // throws BADINDEX
virtual void erase() =0;
};
Node.h
template <class T>
class Node {
public:
T data;
Node<T> *next;
Node(T e) {
data = e;
next = NULL;
}
};
MyList.h
#include "ContainerIfc.h"
#include "Node.h"
template <class T>
class MyList : public ContainerIfc <T> {
public:
MyList();
~ MyList();
MyList(const MyList&);
MyList <T>& operator = (const MyList&);
MyList <T>& pushFront(T);
MyList <T>& pushBack(T);
MyList <T>& popFront(T&);
MyList <T>& popBack(T&);
int getSize();
bool isEmpty();
T front();
T back();
T& operator [](int);
void erase();
protected:
Node<T> *head;
};
I need to complete the experiment of all Functions in Mylist and I cannot change the content in ContainerIfc.h and Node.h, and I also need to write a main.cpp to test all functions in MyList.h. The main thing is that I can't make changes in Containerifc.h and Node.h, which makes me very uncomfortable and don't know how to do it.