תור קדימויות ב CPP

helloworld5

New member
תור קדימויות ב CPP

אהלן
http://www.cplusplus.com/reference/queue/priority_queue/
אני יודע כמובן מה זה תור קדימויות
כמו כן ראיתי https://www.youtube.com/watch?v=DHuJ-n-L8Ko שמראה על השימוש(גם את זה ידעתי)
2 שאלות בבקשה
1- כיצד ניתן דרך ה STL כמובן, לעשות תור קדימויות הפוך 'שהמינימום יהיה למעלה, יש משהו מובנה בשפה?
2- אם לתור אני לא מכניס מספרים INT כמו שם, אלא רוצה להכניס אובייקטים,
לדוגמה מחלקה שמכילה תעודת זהות וגיל , ואני רוצה שהתור קדימויות יפעל לפי הגיל, כיצד ניתן להגדיר זאת?
תודה
 

bismark1

New member
קרא עד הסוף - שים לב שאתה מעביר לו comperator

מתוך הלינק שאתה שמת:
A binary predicate that takes two elements (of type T) as arguments and returns a bool.
The expression comp(a,b), where comp is an object of this type and a and b are elements in the container, shall return true if a is considered to go before b in the strict weak ordering the function defines.
The priority_queue uses this function to maintain the elements sorted in a way that preserves heap properties(i.e., that the element popped is the last according to this strict weak ordering).
This can be a function pointer or a function object, and defaults to less<T>, which returns the same as applying theless-than operator (a<b).

כלומר - הגדרת הסדר "הנכון" בין האובייקטים היא בשליטתך (ואגב, שים לב שזה תופס להרבה פונקציות ב-STL).
 
למעלה