Page 1 of 1

Initialize a Queue Empty

Posted: Fri Jul 27, 2007 11:16 am
by Kallol
suppose i have declared :

queue<int> Q;

I want this Q empty at the beginning of each interation:

t=0;
while(t--)
{
//here I need the Queue empty

// here are oprations with that Q which may leave the queue un-empty at the end
}

what should I do to make my Q empty each time ??

Thanks in advance

Posted: Fri Jul 27, 2007 12:50 pm
by sunny
EDITED

Posted: Fri Jul 27, 2007 6:15 pm
by mf

Code: Select all

Q = queue<int>();

Posted: Fri Jul 27, 2007 8:03 pm
by Kallol
thanks , its working fine now :)

Posted: Tue Aug 07, 2007 7:29 am
by Quantris
You could also make your queue variable local to the while loop, since that seems to be the only place you use it.

Re: Initialize a Queue Empty

Posted: Wed Oct 29, 2014 6:27 pm
by Zyaad Jaunnoo
Place the variable inside your while loop.

Code: Select all

t=10; 
while(t--) 
{ 
  queue<int> Q;        //here I need the Queue empty 

  // here are oprations with that Q which may leave the queue un-empty at the end 
}