title: Writing a LinkedList destructor?
body: <p>Is this a valid LinkedList destructor? I'm still sort of confused by them.</p>
  
  <p>I want to make sure I'm understanding this correctly.</p>
  
  <pre><code> LinkedList::~LinkedList()
   {
     ListNode *ptr;
  
     for (ptr = head; head; ptr = head)
     {
       head = head-&gt;next
       delete ptr;
     }
  }
  </code></pre>
  
  <p>So at the beginning of the loop, pointer ptr is set to hold the address of head, the first node in the list. head is then set to the next item, which will become the beginning of the list once this first deletion takes place. ptr is deleted, and so is the first node. With the first iteration of the loop, pointer is set to head again.</p>
  
  <p>The thing that concerns me is reaching the very last node. The condition "head;" should check that it is not null, but I'm not sure if it will work.</p>
  
  <p>Any help appreciated.</p>