title: Remove all item from queue c++
body: <p>If I have a queue implemented as a series of nodes (value, pointer to next node), what would be the best way to transverse that queue and check for a specific value, and edit the queue such that all nodes containing that value would be removed. But the order of the queue would otherwise remain.</p>
  
  <p>Ok here is the header describing all the functions</p>
  
  <pre><code>class queue
  {
    public:
      queue(); // constructor - constructs a new empty queue.
      void enqueue( int item ); // enqueues item.
      int dequeue();  // dequeues the front item.
      int front();   // returns the front item without dequeuing it.
      bool empty();  // true iff the queue contains no items.
      int size();  // the current number of items in the queue.
      int remove(int item); // removes all occurrances of item 
        // from the queue, returning the number removed.
  
    private:
      class node  // node type for the linked list 
      {
         public:
             node(int new_data, node * next_node ){
                data = new_data ;
                next = next_node ;
             }
             int data ;
             node * next ;
      };
  
      node* front_p ;
      node* back_p ;
      int current_size ; // current number of elements in the queue.
  };
  </code></pre>
  
  <p>and here is the queue.cpp</p>
  
  <pre><code>#include "queue.h"
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  queue::queue()
  {
     front_p = NULL;
     back_p = NULL;
     current_size = 0;
  }
  
  void queue::enqueue(int item)
  {
      node* newnode = new node(item, NULL);
     if (front_p == NULL) //queue is empty
          front_p = newnode;
      else
          back_p-&gt;next = newnode;
     back_p = newnode;
     current_size ++;
  }
  
  int queue::dequeue()
  {
     //if there is only one node
      int value = front_p-&gt;data;
      if (front_p == back_p)
      {
          front_p = NULL;
          back_p = NULL;
      }
      //if there are two or more
      else
      {
          node* temp = front_p;
          front_p = temp-&gt;next;
          delete temp;
      }
      current_size --;
      return value;
  }
  
  int queue::front()
  {
      if (front_p != NULL)
          return front_p-&gt;data;
  }
  
  bool queue::empty()
  {
      if (front_p == NULL &amp;&amp; back_p == NULL)
          return true;
      else
          return false;
  }
  
  int queue::size()
  {
      return current_size;
  }
  
  int queue::remove(int item)
  {
  //?????
  }
  </code></pre>