Initialize a Queue Empty

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

Moderator: Board moderators

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

Initialize a Queue Empty

Post by Kallol » Fri Jul 27, 2007 11:16 am

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 » Fri Jul 27, 2007 12:50 pm

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 » Fri Jul 27, 2007 6:15 pm

Code: Select all

Q = queue<int>();

User avatar
Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol » Fri Jul 27, 2007 8:03 pm

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 » Tue Aug 07, 2007 7:29 am

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 » Wed Oct 29, 2014 6:27 pm

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++”