473,419 Members | 1,658 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,419 software developers and data experts.

stupid priority_queue

Alright guys, so I'm writting in c++ and I have an instance of the priority_queue class which i am filling with instances of this structure:

Expand|Select|Wrap|Line Numbers
  1. struct app
  2.     {
  3.         int idTag;
  4.         int date, hours, mins;
  5.         string appmonth, fname, lname, ampm;
  6.     };
  7.  
I know the priority_queue automatically sorts its contents and pops them from larger to smaller, but with my structure intances it is just poping them in the order that i enter them, and not sorting them at all (i guess because there is no way for it to tell one structure instance greater than another). So what I want to do is tell my priority_queue to look at at the "int idTag" variable and sort itself according to that. is there any kind of overloading or something i can do to make it do that?? thanks in advance for you help, everyone.
Apr 8 '07 #1
1 1389
JosAH
11,448 Expert 8TB
Alright guys, so I'm writting in c++ and I have an instance of the priority_queue class which i am filling with instances of this structure:

Expand|Select|Wrap|Line Numbers
  1. struct app
  2.     {
  3.         int idTag;
  4.         int date, hours, mins;
  5.         string appmonth, fname, lname, ampm;
  6.     };
  7.  
I know the priority_queue automatically sorts its contents and pops them from larger to smaller, but with my structure intances it is just poping them in the order that i enter them, and not sorting them at all (i guess because there is no way for it to tell one structure instance greater than another). So what I want to do is tell my priority_queue to look at at the "int idTag" variable and sort itself according to that. is there any kind of overloading or something i can do to make it do that?? thanks in advance for you help, everyone.
As I told you already in your other thread: define an overloaded operator<
either as a member or as an ordinary function (all struct members are public
so there's no need for a friend declaration).

Expand|Select|Wrap|Line Numbers
  1. bool operator<(const struct app& a, const struct app& b) {
  2.    return a.idTag < b.idTag;
  3. }
The struct value with the highest idTag value is considerd the one with the
highest priority. As always: RTFM.

kind regards,

Jos
Apr 8 '07 #2

Sign in to post your reply or Sign up for a free account.

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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.