Doubly linked list in C++ Please, review the code:

#include &lt;iostream&gt;
using namespace std;

template &lt;class T&gt;
struct Node
{
  Node(T data) : data(data), next(NULL), prev(NULL) {}
  T data;
  Node * next;
  Node * prev;
};

template &lt;class T&gt;
class DoublyLinkedList
{
public:
  DoublyLinkedList() : head(NULL), tail(NULL) {}
  DoublyLinkedList(const DoublyLinkedList&lt;T&gt; &amp; dll);
  ~DoublyLinkedList();
  void addNode(T data);
  //void insertNodeBefore(int data, int before);
  //void insertNodeAfter(int data, int after);
  void deleteNode(T data);
  template &lt;class U&gt;
  friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const DoublyLinkedList&lt;U&gt; &amp; dll);
private:
  Node&lt;T&gt; * head;
  Node&lt;T&gt; * tail;
};

template &lt;class U&gt;
std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const DoublyLinkedList&lt;U&gt; &amp; dll)
{
  Node&lt;U&gt; * tmp = dll.head;
  while (tmp)
    {
      os &lt;&lt; tmp-&gt;data &lt;&lt; " ";
      tmp = tmp-&gt;next;
    }

  return os;
}

template &lt;class T&gt;
DoublyLinkedList&lt;T&gt;::~DoublyLinkedList()
{
  Node&lt;T&gt; * tmp = NULL;
  while (head)
    { 
      tmp = head;
      head = head-&gt;next;
      delete tmp;
    }
  head = tail = NULL;
}

template &lt;class T&gt;
void DoublyLinkedList&lt;T&gt;::addNode(T data)
{
  Node&lt;T&gt; * t = new Node&lt;T&gt;(data);

  Node&lt;T&gt; * tmp = head;
  if (tmp == NULL)
    {
      head = tail = t;
    }
  else
    {
      while (tmp-&gt;next != NULL)
        {
          tmp = tmp-&gt;next;
        }

      tmp-&gt;next = t;
      t-&gt;prev = tail;

      tail = t;
    }
}

template &lt;class T&gt;
void DoublyLinkedList&lt;T&gt;::deleteNode(T data)
{
  Node&lt;T&gt; * tmp = head;
  while (tmp &amp;&amp; tmp-&gt;data != data)
    {
      tmp = tmp-&gt;next;
    }

  if (tmp)
    {
      if (tmp-&gt;prev &amp;&amp; tmp-&gt;next) // no change to head or tail
        {
          tmp-&gt;prev-&gt;next = tmp-&gt;next;
          tmp-&gt;next-&gt;prev = tmp-&gt;prev;
        }
      else if (tmp-&gt;prev) // change to tail
        {
          tmp-&gt;prev-&gt;next = tmp-&gt;next;
          tail = tmp-&gt;prev;
        }
      else if (tmp-&gt;next) // change to head
        {
          tmp-&gt;next-&gt;prev = tmp-&gt;prev;
          head = tmp-&gt;next;
        }

      delete tmp;
    }
}

template &lt;class T&gt;
DoublyLinkedList&lt;T&gt;::DoublyLinkedList(const DoublyLinkedList&lt;T&gt; &amp; dll)
{
  Node&lt;T&gt; * tmp = dll.head;
  while (tmp)
    {
      this-&gt;addNode(tmp-&gt;data);
      tmp = tmp-&gt;next;
    }
}

int main()
{
  DoublyLinkedList&lt;int&gt; dll;

  dll.addNode(1);
  dll.addNode(2);
  dll.addNode(3);
  dll.addNode(4);
  dll.addNode(5);

  cout &lt;&lt; dll &lt;&lt; endl;
  DoublyLinkedList&lt;int&gt; dll2(dll);
  cout &lt;&lt; dll2 &lt;&lt; endl;

  dll.deleteNode(3);
  dll.deleteNode(1);
  dll.deleteNode(5);

  cout &lt;&lt; dll &lt;&lt; endl;
  cout &lt;&lt; dll2 &lt;&lt; endl;

  return 0;
}
Consider replacing Node&lt;T&gt; with:

typedef Node&lt;T&gt; node_t;

...

node_t node;

Consider making your implementation STL-enabled. If I were user of this class, the first thing I'd ask you is "how do I iterate over this list?". Doubly-linked lists are great when adding items in the middle, how do I do it? (it's about operations like insertBefore(), insertAfter()). How do I sort it? How do I check if item is on the list? How do I search using predicate?
Why do you call the method deleteNode if it's only argument is of type T? It's more to findNodeByValueAndDeleteIt(T).
What about assignment operator? You should either declare it private (if you don't support it), or implement it explicitly depending on semantics you want to support (deep copy (most likely what you want), reference, COW, etc):

YourList&lt;int&gt; a; // do something with a

YourList&lt;int&gt; b; // do something with b

a = b; // what is "a" here? what if I add nodes to a? will it affect b?

// imagine, scope ends here, dtor for b is called, everything's fine

// dtor for a is called - here you're going to crash, since

// both a and b were using the same memory and this memory is already

// free, since b's dtor has already been called at this point

For methods like void addNode(T data) - why do you pass data by value? Since you store item values by value, in either case you're going to call their copy-ctor. Copy-ctor requires const-reference, so you should consider replacing addNode with void addNode(T const&amp; data).
using namespace std; - is it only for cout instead of std::cout in your main()?


Checked nothing from the "algorithmic" standpoint, C++ only.