Linked list(insert at head)
<pre><code>template &lt;class T&gt;
List&lt;T&gt;::~List()
{                
   ListItem&lt;T&gt; *temp,*temp1;
   temp=head;         
   while (temp-&gt;next!=NULL)         
   {
          temp1=temp;
          temp=temp-&gt;next;
          delete [] temp1;
   }        
}

/* This class just holds a single data item. */ 
template &lt;class T&gt;
struct ListItem
{
vector&lt;string&gt; words;
T value;
ListItem&lt;T&gt; *next;
ListItem&lt;T&gt; *prev;

ListItem(T theVal)
{
    this-&gt;value = theVal;
    this-&gt;next = NULL;
    this-&gt;prev = NULL;
}
};

template &lt;class T&gt;
void List&lt;T&gt;::insertAtHead(T item)
{
 ListItem&lt;T&gt; *node=new ListItem&lt;T&gt;(item);
 if (head==NULL)
 {
     head=node;
 }
 else
 {
     node-&gt;next=head;
     head-&gt;prev=node;
     head=node;
 }           
}
int main()
{
List&lt;int&gt; Mylist;
for (int i=20;i&gt;0;--i)
{
    Mylist.insertSorted(i);
}
cout&lt;&lt;Mylist.getTail()-&gt;value&lt;&lt;endl;
system("PAUSE");
return 0;
</code></pre>

<p>}</p>

<p>I am making a linked list using classes and template.When I run this code,it runs fine but when i press a key to exit,the following error appears:"main.exe has stopped working"
I am using Dev c++.I have added the destructor code.I don't see any problem in it. </p>
