âšī¸ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.8 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.geeksforgeeks.org/cpp/multiple-comparisons-in-a-c-priority-queue/ |
| Last Crawled | 2026-03-16 22:43:40 (24 days ago) |
| First Indexed | 2025-07-03 04:30:26 (9 months ago) |
| HTTP Status Code | 200 |
| Meta Title | Multiple comparisons in a C++ priority queue? - GeeksforGeeks |
| Meta Description | Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more., Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. |
| Meta Canonical | null |
| Boilerpipe Text | null |
| Markdown | [](https://www.geeksforgeeks.org/)
- Courses
- Tutorials
- Interview Prep
- [C++ Tutorial](https://www.geeksforgeeks.org/cpp/c-plus-plus/)
- [Interview Questions](https://www.geeksforgeeks.org/cpp/cpp-interview-questions/)
- [Examples](https://www.geeksforgeeks.org/cpp/cpp-programming-examples/)
- [Quizzes](https://www.geeksforgeeks.org/cpp/c-programming-multiple-choice-questions/)
- [Projects](https://www.geeksforgeeks.org/cpp/top-50-cpp-project-ideas-for-beginners-advanced/)
- [Cheatsheet](https://www.geeksforgeeks.org/cpp/cpp-cheatsheet/)
- [OOP](https://www.geeksforgeeks.org/cpp/object-oriented-programming-in-cpp/)
- [Exception Handling](https://www.geeksforgeeks.org/cpp/exception-handling-c/)
- [STL](https://www.geeksforgeeks.org/cpp/the-c-standard-template-library-stl/)
- [DSA C++](https://www.geeksforgeeks.org/cpp/learn-dsa-in-cpp/)
# Multiple comparisons in a C++ priority queue?
Last Updated : 23 Jul, 2025
## What is a Priority Queue?
A Priority Queue is an abstract data type that is similar to a queue, and every element has some priority value associated with it. The priority of the elements in a priority queue determines the order in which elements are served (i.e., the order in which they are removed). If in any case, the elements have the same priority, they are served as per their ordering in the queue.
To learn more about priority queue, refer to the article on "[**Introduction to Priority Queue**](https://www.geeksforgeeks.org/dsa/priority-queue-set-1-introduction/)".
## What is priority\_queue STL in C++?
A '[**priority\_queue**](https://www.geeksforgeeks.org/cpp/priority-queue-in-cpp-stl/)' is a container adaptor that provides us with a constant time lookup of the largest element at the expense of logarithmic insertion and extraction. We can use a user-provided compare function to change the order e.g. using **std::greater\<T\>** would cause the smallest element to appear at the top.
When we are using the priority queue we are basically using a heap in some random access container, which has the benefit of not being able to accidentally invalidate the given heap.
## Priority Queue with a Custom Comparator
> Custom comparators are static functions that are used to define the parameter on which the given container is going to be sorted. It determines the way in which the given container is going to be sorted.
If we use a **'\>'** symbol then we are trying to sort in the ascending order else we are trying to sort in the descending order as '**\>**' will return true when **a \> b** (**a** is greater than **b**) else it will return false. So a swap will take place if the comparator is going to return false else no swap is going to take place.
Let's see a program and further understand how this concept is going to be applied.
C++
``
**Output**
```
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9
```
Here we see how the comparator is used to compare the defined datatypes and sort the data according to the comparator that we have given.
## Multiple Comparisons in a C++ Priority Queue
Next, we are going to make multiple comparisons using the priority queue on a user-defined data type and then we are going to sort the data that has been given to us.
We can build a comparator function that compares more than one parameter and sort the data structure based on the conditions provided in the comparator. Below is an implementation of multiple comparisons in C++ priority queue.
C++
``
**Output**
```
0 9 10 5 somejob8
0 8 7 6 somejob7
3 3 2 4 somejob2
4 2 3 3 somejob1
6 1 1 6 somejob0
7 5 5 3 somejob4
7 4 5 4 somejob3
10 10 10 6 somejob9
10 7 7 5 somejob6
10 6 5 4 somejob5
```
Comment
Article Tags:
Article Tags:
[C++](https://www.geeksforgeeks.org/category/programming-language/cpp/)
[cpp-priority-queue](https://www.geeksforgeeks.org/tag/cpp-priority-queue/)
### Explore
[](https://www.geeksforgeeks.org/)

Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)

Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
[](https://geeksforgeeksapp.page.link/gfg-app)[](https://geeksforgeeksapp.page.link/gfg-app)
- Company
- [About Us](https://www.geeksforgeeks.org/about/)
- [Legal](https://www.geeksforgeeks.org/legal/)
- [Privacy Policy](https://www.geeksforgeeks.org/legal/privacy-policy/)
- [Contact Us](https://www.geeksforgeeks.org/about/contact-us/)
- [Advertise with us](https://www.geeksforgeeks.org/advertise-with-us/)
- [GFG Corporate Solution](https://www.geeksforgeeks.org/gfg-corporate-solution/)
- [Campus Training Program](https://www.geeksforgeeks.org/campus-training-program/)
- Explore
- [POTD](https://www.geeksforgeeks.org/problem-of-the-day)
- [Job-A-Thon](https://practice.geeksforgeeks.org/events/rec/job-a-thon/)
- [Blogs](https://www.geeksforgeeks.org/category/blogs/?type=recent)
- [Nation Skill Up](https://www.geeksforgeeks.org/nation-skill-up/)
- Tutorials
- [Programming Languages](https://www.geeksforgeeks.org/computer-science-fundamentals/programming-language-tutorials/)
- [DSA](https://www.geeksforgeeks.org/dsa/dsa-tutorial-learn-data-structures-and-algorithms/)
- [Web Technology](https://www.geeksforgeeks.org/web-tech/web-technology/)
- [AI, ML & Data Science](https://www.geeksforgeeks.org/machine-learning/ai-ml-and-data-science-tutorial-learn-ai-ml-and-data-science/)
- [DevOps](https://www.geeksforgeeks.org/devops/devops-tutorial/)
- [CS Core Subjects](https://www.geeksforgeeks.org/gate/gate-exam-tutorial/)
- [Interview Preparation](https://www.geeksforgeeks.org/aptitude/interview-corner/)
- [Software and Tools](https://www.geeksforgeeks.org/websites-apps/software-and-tools-a-to-z-list/)
- Courses
- [ML and Data Science](https://www.geeksforgeeks.org/courses/category/machine-learning-data-science)
- [DSA and Placements](https://www.geeksforgeeks.org/courses/category/dsa-placements)
- [Web Development](https://www.geeksforgeeks.org/courses/category/development-testing)
- [Programming Languages](https://www.geeksforgeeks.org/courses/category/programming-languages)
- [DevOps & Cloud](https://www.geeksforgeeks.org/courses/category/cloud-devops)
- [GATE](https://www.geeksforgeeks.org/courses/category/gate)
- [Trending Technologies](https://www.geeksforgeeks.org/courses/category/trending-technologies/)
- Videos
- [DSA](https://www.geeksforgeeks.org/videos/category/sde-sheet/)
- [Python](https://www.geeksforgeeks.org/videos/category/python/)
- [Java](https://www.geeksforgeeks.org/videos/category/java-w6y5f4/)
- [C++](https://www.geeksforgeeks.org/videos/category/c/)
- [Web Development](https://www.geeksforgeeks.org/videos/category/web-development/)
- [Data Science](https://www.geeksforgeeks.org/videos/category/data-science/)
- [CS Subjects](https://www.geeksforgeeks.org/videos/category/cs-subjects/)
- Preparation Corner
- [Interview Corner](https://www.geeksforgeeks.org/interview-prep/interview-corner/)
- [Aptitude](https://www.geeksforgeeks.org/aptitude/aptitude-questions-and-answers/)
- [Puzzles](https://www.geeksforgeeks.org/aptitude/puzzles/)
- [GfG 160](https://www.geeksforgeeks.org/courses/gfg-160-series)
- [System Design](https://www.geeksforgeeks.org/system-design/system-design-tutorial/)
[@GeeksforGeeks, Sanchhaya Education Private Limited](https://www.geeksforgeeks.org/), [All rights reserved](https://www.geeksforgeeks.org/copyright-information/) |
| Readable Markdown | null |
| Shard | 103 (laksa) |
| Root Hash | 12046344915360636903 |
| Unparsed URL | org,geeksforgeeks!www,/cpp/multiple-comparisons-in-a-c-priority-queue/ s443 |