title: C++ Deleting a node in Queue
body: <p>Problem1: Deleting in a node in a list > 3</p>
  
  <p>Description:</p>
  
  <p>Deletion of the sixth node in a list of seven, results in a print of only the first
  and last node.</p>
  
  <p>Available Node Pointers:
  *next_, *prev_, *data_</p>
  
  <p>Function to delete the specified node is in the LinkedList.cpp
  Name: DeleteNode.</p>
  
  <p>Function that traverses through the list to print the nodes is in main.cpp
  Name: PrintAllNodes</p>
  
  <p>Possible Solution:</p>
  
  <p>Being able to access Current->prev_ in main when traversing to print the nodes.</p>
  
  <p>Code:</p>
  
  <pre><code>void LinkedList::DeleteNode( Node* node )
  {
      Node *Current = first_; // I want this to be my only Node Ptr Varaible Declaration.
      if ( NULL == first_ )
          std::cout &lt;&lt; "Cannot delete from an empty list: \n";
  //TRAVERSING WAS/IS A BAD IDEA.............................
      while ( Current != NULL )
      {
          if ( Current-&gt;data_ == node-&gt;data_ )
          {
              //If Current isn't the head of the list, set prev to next
              if ( Current != first_ )
              {
                  Current-&gt;prev_        = first_; //statement that follows crashes if this is not assigned.
                  Current-&gt;prev_-&gt;next_ = Current-&gt;next_;
              }
              else
              {
                  first_ = Current-&gt;next_;
                  if ( first_ != NULL )
                  first_-&gt;prev_ = NULL;
              }
  
              //If Current isn't the tail of the list, set next to prev
              if ( Current-&gt;next_ != NULL )
                  Current-&gt;next_ = Current-&gt;prev_;
  
              else if ( Current-&gt;prev_ != NULL )
              Current-&gt;prev_-&gt;next_ = NULL;
  
            listLen_--;
            delete Current;
            Current = NULL;
          }
          else
          {
              Current-&gt;prev_ = Current;
              Current = Current-&gt;next_;
          }
      }
      return;
  }
  </code></pre>
  
  <p>Code for PrintAllNodes in main.cpp:</p>
  
  <pre><code>void PrintAllNodes( LinkedList *LinkedObject, long length = 0 )
  {
      const char *Names = NULL; 
      length = LinkedObject-&gt;GetListLength();
      Node *GetNode = LinkedObject-&gt;GetFirstNode();
  
      for ( signed short x = 0; x &lt; length; x++ )
      {
          Names = static_cast&lt; NameObject* &gt;( GetNode-&gt;data_ )-&gt;GetName();
          cout &lt;&lt; Names &lt;&lt; endl;
          GetNode = GetNode-&gt;next_; // traversing
      }
      return;
  }
  </code></pre>