Removing a node From Doubly Threaded LnkLst
<p>Im trying to remove a single node from a doubly threaded linked list.</p>

<p>What I have works..Its just terribly inefficient. </p>

<p>I was wondering if I can get some expert advice or some while termination condition tips.</p>

<p>Here is the function in which I remove 1 node from a set of Rating Nodes, stored in headByRating and a set of Name nodes, stored in headByName. All of which are sorted....</p>

<pre>
bool list::remove (const char * const name)
{
    node *currByName     = headByName;
    node *currByRating  = headByRating;
    node *prev_node   = NULL;

    while ( NULL != currByName &&
       ( strcmp( name, currByName->item.getName() ) != 0 ) )
     {
      prev_node  = currByName;
      currByName = currByName->nextByName;
      prev_node->nextByName = currByName; 
     }

     if ( currByName == headByName )
     { 
      currByName   = currByName->nextByName;
      headByName   = currByName;
     }
      else if ( currByName->nextByName == NULL )
      {//then we must be at the end
       currByName = prev_node;
       currByName->nextByName = NULL;
       //return true;
      }
      else
      {
       currByName = prev_node;
       currByName->nextByName = currByName->nextByName->nextByName;
       //return true;
      }

    while ( NULL != currByRating && 
       ( strcmp( name, currByRating->item.getName() ) != 0 ) )
    {
     prev_node = currByRating;
     currByRating = currByRating->nextByRating;
     prev_node->nextByRating  = currByRating;
    }
     if ( currByRating == headByRating ) // was it the head?
     {
      currByRating = currByRating->nextByRating;
      headByRating = currByRating;
      return true;
     }
     else if ( currByRating->nextByRating == NULL ) // could it be the tail?
     {
      currByRating = prev_node;
      currByRating->nextByRating = NULL;
      return true;
     }
     else
     {
      currByRating = prev_node;
      currByRating->nextByRating = currByRating->nextByRating->nextByRating;
      return true;
     }


    return false;
}</pre>

<p>Yeah i just need help simplifing the code, making it more efficient. I hoping to combine and use only one while loop if thats possible. </p>
