I am currently in a data-structures class. The professor will be providing a singly linked list. I wanted to make a doubly linked list to learn how to do it. I tested it and I think it works. After making it, I did compare it to other doubly linked lists but I still want to see if there is anything I am missing.  Are there any other problems with it?LinkNode Class:#ifndef LINKNODE_H_#define LINKNODE_H_#include <iostream>template<class E>class LinkNode {public:    E data;    LinkNode<E> *leftNode;    LinkNode<E> *rightNode;    LinkNode() {    }    LinkNode(E e) {        this->data = e;    }    ~LinkNode() {    }    E getData() {        return data;    }    void setData(E e) {        this->data = e;    }    LinkNode<E> getLeftNode() {        return leftNode;    }    void setLeftNode(LinkNode<E> node) {        this->leftNode = node;    }    LinkNode<E> getRightNode() {        return rightNode;    }    void setRightNode(LinkNode<E> node) {        this->rightNode = node;    }};#endif /* LINKNODE_H_ */LinkedList Class:    #ifndef LINKEDLIST_H_#define LINKEDLIST_H_#include LinkNode.htemplate<class T>class LinkedList {private:    int size;    LinkNode<T> *firstNode;    LinkNode<T> *lastNode;public:    LinkedList() {        firstNode = new LinkNode<T>();        lastNode = firstNode;        size = 0;    }    ~LinkedList() {    }    void pushFront(T t) {        if (size == 0) {            pushBack(t);            return;        }        LinkNode<T> *linkNode = new LinkNode<T>(t);        linkNode->rightNode = firstNode;        firstNode->leftNode = linkNode;        firstNode = linkNode;        size++;    }    void pushBack(T t) {        LinkNode<T> *linkNode = new LinkNode<T>(t);        linkNode->leftNode = lastNode;        lastNode->rightNode = linkNode;        lastNode = linkNode;        if (size == 0) {            firstNode = lastNode;        }        size++;    }    T pollFirst() {        T t = firstNode->data;        firstNode = firstNode->rightNode;        size--;        return t;    }    T pollLast() {        T t = lastNode->data;        lastNode = lastNode->leftNode;        size--;        return t;    }    LinkNode<T> getFirstNode() {        return firstNode;    }    LinkNode<T> getLastNode() {        return lastNode;    }    T searchNode(T t) {        return t;    }    int Size() {        return size;    }    void printLinkedList() {        LinkNode<T> *temp = firstNode;        while (temp != NULL) {            std::cout << temp->data << \t;            temp = temp->rightNode;        }    }};#endif /* LINKEDLIST_H_ */New LinkedList Class:#ifndef LINKEDLIST_H_#define LINKEDLIST_H_#include <iostream>template<class T>class LinkedList {    /**     * Private inner node class     */    //Have to use new template. Does not run if I try to use T    template<class E>    class LinkNode {    public:        E data;        LinkNode<E> *leftNode;        LinkNode<E> *rightNode;        LinkNode() {        }        LinkNode(E e) {            this->data = e;        }        ~LinkNode() {        }    };private:    int size;    LinkNode<T> *firstNode;    LinkNode<T> *lastNode;public:    LinkedList() {        firstNode = new LinkNode<T>();        /*         * Init left and right node to null to prevent exception.         */        firstNode->leftNode = NULL;        firstNode->rightNode = NULL;        lastNode = firstNode;        size = 0;    }    ~LinkedList() {        LinkNode<T> *linkNode = firstNode->rightNode;        while (linkNode != NULL) {            delete linkNode->leftNode;            linkNode = linkNode->rightNode;        }    }    void pushFront(T t) {        //the size is zero therefore we are really justing pushing to the back of the linked list        if (size == 0) {            pushBack(t);            return;        }        LinkNode<T> *linkNode = new LinkNode<T>(t);        linkNode->rightNode = firstNode;        firstNode->leftNode = linkNode;        firstNode = linkNode;        size++;    }    void pushBack(T t) {        LinkNode<T> *linkNode = new LinkNode<T>(t);        linkNode->leftNode = lastNode;        lastNode->rightNode = linkNode;        lastNode = linkNode;        if (size == 0) {            firstNode = lastNode;        }        size++;    }    T pollFirst() {        LinkNode<T> *temp = firstNode;        T t = firstNode->data;        firstNode = firstNode->rightNode;        delete temp;        size--;        return t;    }    T pollLast() {        LinkNode<T> *temp = lastNode;        T t = lastNode->data;        lastNode = lastNode->leftNode;        delete temp;        size--;        return t;    }    LinkNode<T> getFirstNode() {        return *firstNode;    }    LinkNode<T> getLastNode() {        return *lastNode;    }    int const Size() {        return size;    }    void const printLinkedList() {        LinkNode<T> *temp = firstNode;        while (temp != NULL) {            std::cout << temp->data << \t;            temp = temp->rightNode;        }    }};#endif /* LINKEDLIST_H_ */Xubuntu 13.10GCC Compiler installed with sudo apt-get install g++
Validity of doubly linked list
c++;linked list
New Linked List ClassThis is a review of the new New Linked List Class.Here you wrote://Have to use new template. Does not run if I try to use Ttemplate<class E>class LinkNode {public:    E data;    LinkNode<E> *leftNode;    LinkNode<E> *rightNode;    LinkNode() {    }    LinkNode(E e) {        this->data = e;    }    ~LinkNode() {    }};I said, LinkNode is no longer a template class: it's a nested class of a template class.You said you don't want to read my code, but here's my code ahead:    // Not a template class.    // template<class E>    class LinkNode {    public:        E data;        LinkNode *leftNode;        LinkNode *rightNode;        LinkNode() {        }        LinkNode(E e) {            this->data = e;        }        ~LinkNode() {        }    };private:    int size;    LinkNode *firstNode;    LinkNode *lastNode;In C++, unlike in Java, members are not auto-initialized to 0. Maybe your compiler leaves them initialized to 0, but mine doesn't. Your compiler is probably leaving you with uninitialized memory, which happened to be zero-filled, but which would no longer be zero-filled if your program had been running for longer with lots of previous news and deletes.If I do printLinkedList after the first push, it crashes. That's because your push method is like this:void pushBack(T t) {    LinkNode<T> *linkNode = new LinkNode<T>(t);    linkNode->leftNode = lastNode;    lastNode->rightNode = linkNode;    lastNode = linkNode;    if (size == 0) {        firstNode = lastNode;    }    size++;}It doesn't initialize the rightNode member of the new linkNode.You probably want to initialize everything in your LinkNode constructor: set leftNode and rightNode to 0.Before the first push, firstNode and lastNode point to your initial, empty, 'sentinel' node.After the first push, firstNode and lastNode point to the new node, and the new node's leftNode points to your sentinel node.Then after the next pushFront, nothing is pointing to your sentinel node. If you're going to lose your sentinel node from the list, I don't see any good reason for creating it in the first place. (The solution I proposed in my other answer doesn't create an initial sentinel node, and instead sets and expects firstNode and lastNode to be NULL when the list is empty).If I call printLinkedList before I push anything onto the list, it prints the value (possibly 0, possibly something else) contained in your initial, empty, sentinel node.If I run the following test code then it prints an infinite number of 2s:LinkedList<int> linked;linked.printLinkedList();linked.pushFront(10);linked.printLinkedList();linked.pollFirst();linked.printLinkedList();linked.pushBack(2);linked.printLinkedList();