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 7180599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:22:57+00:00 2026-05-28T17:22:57+00:00

I am implementing a generic Priority Queue as part of a homework project. I

  • 0

I am implementing a generic Priority Queue as part of a homework project. I am wondering what to return when the PriorityQueue is empty. I could not return null.

What is the best method to handle this case? What is the best design choice when implementing such datastructures?

class PQueue<T> : IPQueue<T>
{
    T[] items;
    //..

    public T RemoveMax()
    {
        if(heapSize < 1)    //Heap Empty
             return default(T);

        T max = items[0];
        //..

        return max;
    }
}
  • 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-05-28T17:22:58+00:00Added an answer on May 28, 2026 at 5:22 pm

    I would look for guidance in the framework classes here, i.e. Queue<T> – which throws an InvalidOperationException if you try and dequeue an item from an empty queue. This only makes sense though if you give consumers access to the number of items in the queue or at least if the queue is empty or not, i.e.:

    public bool IsEmpty()
    {
       return heapSize == 0;
    }
    
    public int Count
    {
      get 
      {
        return heapSize;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a generic PriorityQueue in C# as part of homework. The items
i'm implementing a generic interface (iqueryprovider, specifically). at some point, i'm forced to return
I'm working on a C project implementing some generic containers and am having this
I'm toying with the idea of implementing a generic Producer/Consumer pair + processing queue
What is the best way to implement a tree structure (generic - not binary)
I'm implementing generic, persistent .NET collections based on top of the ESENT database engine
A couple of days ago, I read a blog entry ( http://ayende.com/Blog/archive/2008/09/08/Implementing-generic-natural-language-DSL.aspx ) where
Fixed: See notes at bottom I am implementing a generic class that supports two
I am looking for good ideas for implementing a generic way to have a
So in a previous question I asked about implementing a generic interface with a

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.