Sorting Doubly Linked List C++
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1382273/sorting-a-doubly-linked-list-c-question">Sorting a Doubly Linked List C++ Question</a>  </p>
</blockquote>



<p>as of right now the sort function that I have only sorts 1 node out of the many. </p>

<p>I need this function disregard the node that is sorted only after it is printed. </p>

<p>I've tried removing the node so that it is not considered twice for the sort, because It will keep printing that same sorted node over and over again. That didnt work so here i am.</p>

<p>This is defined and its where I call my sorting function. It has one node *Paramater and returns a node.</p>

<pre><code>void list::displayByName(ostream&amp; out) const
{
 node *current_node  = headByName; // is  @the head of the list
 node *evil_node     = tail;

 while ( current_node != NULL )
 {
  current_node = sort( current_node );
  out &lt;&lt; current_node-&gt;item.getName() &lt;&lt; endl;
 }
}
</code></pre>

<p>Defined as a private function of my list class.</p>

<pre><code>list::node * const list::sort( node *given_node ) const
{ 
 node *least_found_node = NULL;
 node *current_node    = given_node-&gt;nextByName;

 while ( current_node &amp;&amp; current_node != given_node ) // while current_node != NULL and..
 {   
  if ( strcmp( current_node-&gt;item.getName(), given_node-&gt;item.getName() ) &lt; 0 )
  {
   if ( least_found_node == NULL ||  
      ( strcmp( least_found_node-&gt;item.getName(), current_node-&gt;item.getName() ) &gt; 0 ) )
   {
    least_found_node = current_node;
   }
  }
  current_node = current_node-&gt;nextByName;

 }

 return least_found_node; // return that sorted node
}
</code></pre>
