473,485 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Still priority queues and STL ...

I posted this reaction in a thread quite far below so I fear people won't
read it. I got stuck now for quite a while and just don't know what to try
else.
Thanks,
Matthias
Are priority queues implemented in the STL in Visual Studio 6? If no, which
is the easiest way to simulate them? Multisets?
BTW: The container contains pointers to instances of a class. The ordering of the elements must follow the value of the class-instances not the value of the pointers. Furthermore, elements are inserted throughout execution

of
the program so I need a insert function which keeps the elements sorted; a sort function which sorts the whole container after every insertion is not sufficient (and surely not efficient).


See template class priority_queue in the header <queue>. You'll
have to supply an ordering predicate that takes two pointers
and returns true when one of the designated objects is ordered
before the other, but that shouldn't be hard.


The following sample program does not compile but I have no idea what to do
about it. Might be a beginner's fault. If I substitute pv(comp()) with
pv(std::less<Vertex*>()) the compiler gives no error, but I strongly suppose
less() would order the elements according to the address value of the
pointer.

#include <queue>

struct Vertex
{
int a;
};

bool comp (Vertex* v1, Vertex* v2)
{
return v1->a < v2->a;
}

int main()
{
std::priority_queue<Vertex*> pv(comp());
return 0;
}

Regards,
Matthias

the pointers in a random-access container, which it maintains
as a heap. Pushing new items on the heap and popping the highest
priority items off the heap each take log(N) percolations, where
N is the total size of the heap (queue). Hard to do better.



Jul 22 '05 #1
1 1763
On Fri, 4 Jun 2004 18:09:39 +0200 in comp.lang.c++, "Der Andere"
<ma**************@gmx.net> wrote,
The following sample program does not compile but I have no idea what to do
about it. Might be a beginner's fault. If I substitute pv(comp()) with
pv(std::less<Vertex*>()) the compiler gives no error, std::priority_queue<Vertex*> pv(comp());


1. You do not want to pass to the constructor the result of calling
comp() but rather the address of the function &comp.

2. The type of the comparator is a template parameter of
priority_queue, so if you want to use something other than the default
std::less you must spell it all out.

std::priority_queue<Vertex*, std::vector<Vertex *>,
bool(*)(Vertex *, Vertex *) > pv(&comp);

Jul 22 '05 #2

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

Similar topics

0
1423
by: aaronwmail-usenet | last post by:
I've been wondering about benchmarks recently. What is a fair benchmark? How should benchmarks be vetted or judged? I decided to see what you folks thought, so for discussion I compared two...
38
5729
by: Aaron W. LaFramboise | last post by:
Hello, I understand that an easy way to make the standard std::priority_queue stable is by including an integer stamp with each node that is incremented each time a new node is pushed into the...
6
2465
by: Der Andere | last post by:
Are priority queues implemented in the STL in Visual Studio 6? If no, which is the easiest way to simulate them? Multisets? BTW: The container contains pointers to instances of a class. The...
1
2886
by: Jim Strathmeyer | last post by:
So, I've been looking for a wrapper class for STL priority queues, and haven't been able to find one. (Websearching for info about the STL sure shows how much it's changed over the past few years.)...
5
13200
by: Dan H. | last post by:
Hello, I have implemented a C# priority queue using an ArrayList. The objects being inserted into the priority queue are being sorted by 2 fields, Time (ulong) and Priority (0-100). When I...
3
7032
by: eric.boissard | last post by:
Hello, I managed to implement the AStar algorithm, however I have some trouble using the priority queue, and the 'compare' function. Here is my 'Waypoint.h' header file: class Waypoint {...
8
3655
by: vidishasharma | last post by:
Can somebody suggest good URL which contains code for merging of 2 or more priority queues in c#.
5
1673
by: kidfiction | last post by:
Hello again, I was wondering if you could make priority queues with defined compare functions out of structs rather than objects. Currently I have this (with some things omitted: bool...
1
3948
by: operatingsystem | last post by:
I need to generate such scheduler in operating system subject which satisfy below conditions...may i request u if anybody knows abt this plz help me out in this..topics.. Scheduler...
0
7090
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,...
0
6960
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...
0
7116
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,...
0
5418
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4551
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...
0
3058
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...
0
3063
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1376
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 ...
0
247
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.