473,384 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,384 software developers and data experts.

clearing a priority_queue

Hopefully a simple question:

What is the best/safest/fastest way to clear/make empty a std::priority_queue?

Thanks,
Ryan
Jul 19 '05 #1
4 6333
"Tino" <ti****@yahoo.com> wrote...
Hopefully a simple question:

What is the best/safest/fastest way to clear/make empty a

std::priority_queue?

std::priority_queue myqueue;
... // fill it up

// clear it:
myqueue = std::priority_queue(); // assign an empty one to it

Victor
Jul 19 '05 #2
On Wed, 9 Jul 2003 15:17:01 -0400, "Victor Bazarov"
<v.********@attAbi.com> wrote:
"Tino" <ti****@yahoo.com> wrote...
Hopefully a simple question:

What is the best/safest/fastest way to clear/make empty a

std::priority_queue?

std::priority_queue myqueue;
... // fill it up

// clear it:
myqueue = std::priority_queue(); // assign an empty one to it


Doh! I forgot queues are assignable.

Tom
Jul 19 '05 #3
**** Post for FREE via your newsreader at post.usenet.com ****
"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:vg************@corp.supernews.com...
"Tino" <ti****@yahoo.com> wrote...
Hopefully a simple question:

What is the best/safest/fastest way to clear/make empty a std::priority_queue?

std::priority_queue myqueue;
... // fill it up

// clear it:


When you say "clear it", do you mean that I need to pop off all items? I'm
worried about proper destruction of the elements of the priority_queue. If
this is the case, doesn't

while( myqueue.size() > 0 )
myqueue.pop();

do the job? But is this the fastest way to do it? For std::vector there is
std::vector::clear, and I couldn't find anything analagous for
std::priority_queue.
myqueue = std::priority_queue(); // assign an empty one to it

Victor


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jul 19 '05 #4
"Ryan Martino" <rm******@marketrx.com> wrote in message
news:3f******@post.usenet.com...
**** Post for FREE via your newsreader at post.usenet.com ****
"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:vg************@corp.supernews.com...
"Tino" <ti****@yahoo.com> wrote...
Hopefully a simple question:

What is the best/safest/fastest way to clear/make empty a std::priority_queue?

std::priority_queue myqueue;
... // fill it up

// clear it:


When you say "clear it", do you mean that I need to pop off all items?


No, he means that clears it (hence the colon).

HTH,

Stuart.
I'm
worried about proper destruction of the elements of the priority_queue. If this is the case, doesn't

while( myqueue.size() > 0 )
myqueue.pop();

do the job? But is this the fastest way to do it? For std::vector there is std::vector::clear, and I couldn't find anything analagous for
std::priority_queue.
myqueue = std::priority_queue(); // assign an empty one to it

Victor


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dave | last post by:
Hello all, I'm pondering why the default underlying container for std::priority_queue<> is std::vector<>. It would seem that inserts are liable to happen anywhere, which would make std::list<>...
3
by: Tino | last post by:
In using std::priority_queue, I'm concerned about the expense of memory allocation and copying as the priority_queue grows large. std::vector has reserve() to address this concern, though there...
3
by: zl2k | last post by:
hi, all Here is what I want to do: to wrap my self defined class in a shared_ptr and then insert it into the priority_queue. The priority_queue should pump the least element of the self defined...
9
by: Henning Hasemann | last post by:
I'm using a stl-priority queue and want - find out if a certain item is contained in the queue - to be able iterate over all items without having to pop() them, order does not matter. I couldnt...
18
by: J.M. | last post by:
I would like to use a data structure (e.g. from the STL) that always allows me to retrieve the largest element. (I want to push in elements, and remove the largest, push in further elements, etc.)...
6
by: Eric Lilja | last post by:
Hello, I have a the following priority_queue: priority_queue<pair<int, string pq; AFAICT, priority_queues doesn't support iterators. My question: is there a way to print its contents without...
8
by: thomas | last post by:
priority_queue usually uses the greater<intpredicate function. But as you know, we don't always use priority_queue<int>. Actually we may need the "priority_queue<pair<int,int>,...
24
by: Joe, G.I. | last post by:
Can anyone help me w/ a priority_queue. I'm generating MyEvent classes and I put them on a priority_queue, but I don't know how to get them in priority. The priority is the event w/ the smallest...
5
card
by: card | last post by:
I was wondering if anyone has a definitive answer on whether the STL priority_queue is dynamic? What I mean by this is best illustrated by a simple example. Suppose I have a priority queue of class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.