Initialize a Queue Empty

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Initialize a Queue Empty

Post 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
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
sunny
Experienced poster
Posts: 124
Joined: Sun Sep 11, 2005 10:22 pm
Location: Civil-BUET

Post by sunny »

EDITED
Last edited by sunny on Fri Jul 27, 2007 7:10 pm, edited 1 time in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

Code: Select all

Q = queue<int>();
Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol »

thanks , its working fine now :)
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
Quantris
Learning poster
Posts: 80
Joined: Sat Dec 27, 2003 4:49 am
Location: Edmonton AB Canada

Post 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.
Zyaad Jaunnoo
Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

Re: Initialize a Queue Empty

Post 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 
}
Post Reply

Return to “C++”