void deleteNegative(queue <int> &q)
{
      queue <int> temp;
      
      if (!q.empty())
      {
           int x = q.front();
           
           if (x >= 0)
           {
            temp.push(x);
            q.pop();
           }
           else
           {
            q.pop();
           }    
      }
      
      while(!temp.empty())
      {
       q.push(temp.front());
       temp.pop();
      }

}

just afunction that returns a queue without the negatives in the same order. unsure where ive gone wrong

void deleteNegative(queue <int> &q)
{
      queue <int> temp;
      
      if (!q.empty())
      {
           int x = q.front();
           
           if (x >= 0)
           {
            temp.push(x);
            q.pop();
           }
           else
           {
            q.pop();
           }    
      }
      
      while(!temp.empty())
      {
       cout << temp.front() << " ";
       temp.pop();
      }
}

updated just outputs first number of queue

why have you got a temp, surely you would just pop anything that is negative and that's that.

void deleteNegative(queue <int> &q)

doest the ampersand make a difference?

void deleteNegative(queue <int> &q)
{

      while (!q.empty())
      {
           int x = q.front();
           
           if (x < 0)
           {
           q.pop();
           
           }
           else
           {
            cout << q.front() << " ";
            q.pop();
           }    
      }
      
}

got it working but the "&" is still confusing me

& is pass by reference is that what you require?

yeh im wondering what difference will that fact that its pass by reference make to the code in the deleteNegative function?

This question has already been answered. Start a new discussion instead.