473,569 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clearing a priority_queue

Hopefully a simple question:

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

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

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

std::priority_q ueue?

std::priority_q ueue myqueue;
... // fill it up

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

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

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

std::priority_ queue?

std::priority_q ueue myqueue;
... // fill it up

// clear it:
myqueue = std::priority_q ueue(); // 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.********@att Abi.com> wrote in message
news:vg******** ****@corp.super news.com...
"Tino" <ti****@yahoo.c om> wrote...
Hopefully a simple question:

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

std::priority_q ueue 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::cl ear, and I couldn't find anything analagous for
std::priority_q ueue.
myqueue = std::priority_q ueue(); // 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******@marke trx.com> wrote in message
news:3f******@p ost.usenet.com. ..
**** Post for FREE via your newsreader at post.usenet.com ****
"Victor Bazarov" <v.********@att Abi.com> wrote in message
news:vg******** ****@corp.super news.com...
"Tino" <ti****@yahoo.c om> wrote...
Hopefully a simple question:

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

std::priority_q ueue 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::cl ear, and I couldn't find anything analagous for
std::priority_q ueue.
myqueue = std::priority_q ueue(); // 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
3111
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<> a superior alternative. Why factors am I not considering here? Why in the general case would std::vector<> be best? Thanks, Dave
3
4459
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 doesn't seem to be anything like this for priority_queue. Also, I don't know anything about how priority_queue is implemented (specifically, MSVC++...
3
3999
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 class first. To make it simple, here is the toy code. myClass.h ------------------------------------------ #ifndef MYCLASS_H #define MYCLASS_H
9
28527
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 find methods for these which suprises me as both should be easily solvable with access to the underlying vector. Did I just miss these methods?...
18
5514
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.) It seems a priority_queue from the STL would work fine. However at some point, I am finished (even though the queue is not empty) and want to throw...
6
11181
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 emptying it? Right now I'm using the following code: while (!pq.empty()) { cout << setw(3) << pq.top().first << ": " << pq.top().second <<
8
4154
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>, vector<pair<int,int, cmphp;" thing. My question is how should I write the "cmp" function? I tried this one:
24
2548
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 timestamp. // just a wrapper around priority_queue pq = new MyPriorityQueue(); // I generate 10 events w/ a random timestamp for (int i = 0; i <...
5
3521
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 called Position with a comparator class called PositionCompare as follows: priority_queue<Position, vector<Position>, PositionCompare> _pQ; ...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.