Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:10:56+00:00 2026-06-08T08:10:56+00:00

In C++, with priority queue I can write: priority_queue<int, vector<int>, greater<int>> min_pq; priority_queue<int, vector<int>,

  • 0

In C++, with priority queue I can write:

priority_queue<int, vector<int>, greater<int>> min_pq;
priority_queue<int, vector<int>, less<int>> max_pq;

I wonder is there an equivalent way to do it in C# container? I’m implementing a priority queue, where I need a way to specify this behavior when the user use its constructor. I could use a boolean flag, but it just doesn’t look right to me. Any idea?

public class PriorityQueue<T> where T : IComparable<T> {
     private List<T> data;

     /// <summary>
     /// 
     /// </summary>
     /// <param name="item"></param>
     public void Push(T item) {

     }

     /// <summary>
     /// 
     /// </summary>
     public void Pop() {

     } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:10:58+00:00Added an answer on June 8, 2026 at 8:10 am

    An idiomatic solution in C# is to pass an instance of IComparer<T> to the constructor of your generic class.

    public class PriorityQueue<T> {
        private readonly IComparer<T> comparer;
        public PriorityQueue(IComparer<T> comp = null) {
            comparer = comp ?? Comparer<T>.Default;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wanting to do something like this: priority_queue< pair<int, int>, vector<int>, greater<int> > Q;
With the stl priority_queue you can set the underlying container, such as a vector
I need a priority queue where I can increase or decrease the priority key.
I have declared std::priority_queue like this. priority_queue < Aircraft, vector<Aircraft>, less<Aircraft> > *q; And
Is there any reliable and simple priority queue (linked list preferred, not necessary) implementation
How can I remove an arbitrary item from a priority queue. Suppose I have
I have implemented Priority Queue interface for making heap. Can you tell me how
My quest continues ! I started using a list for my priority queue std::priority_queue<charElement,std::list<charElement>,compareCharElt>
I need a priority queue, I guess in the framework, CHMutableArrayHeap and CHBinaryHeap can
I have a priority queue table that can be simplistically represented as: CREATE TABLE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.