So I have the following class:
template <class T>
class List : public ContainerIfc <T> {
public:
List();
~ List();
List(const List&);
List <T>& operator = (List&);
List <T>& pushFront(T);
List <T>& pushBack(T);
List <T>& popFront(T&);
List <T>& popBack(T&);
int getSize();
bool isEmpty();
T front();
T back();
T& operator [](int);
private:
Node<T> *head;
};
and the following node:
template <class T>
class Node {
public:
T data;
Node<T> *next;
Node(T e) {
data = e;
next = NULL;
}
};
I want to write a pushFront function that adds a value to the front of the linked list. I already have the following code. What I can't figure out is how to get it to return a List object. I think that my function would work as it is, it just wouldn't return a List. Any ideas as to how one might go about doing that?
template <class T>
List <T>& List<T>::pushFront(T n){
Node<T> *temp = new Node<T>(n);
temp->next = head;
}