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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:19:39+00:00 2026-05-27T14:19:39+00:00

I have a list of objects with an enumeration attribute that I wish to

  • 0

I have a list of objects with an enumeration attribute that I wish to sort by. Of the enumeration values, I only care about A, B, and C, and require that in the sorted list, A < B < C. Of values D, E, …, their order doesn’t matter and it doesn’t matter if they are interspersed in the list.

When implementing the comparison, is it necessary to specify a consistent ordering for the extraneous enumeration values relative to the critical values? As an example, does it cause issues if a comparison between A,D results in -1 while the comparison between D,A results in 0, or also -1?

This code is being implemented in C#, which I believe uses quicksort. After reviewing the quicksort algorithm, it looks like this may be an issue if one of the extraneous values becomes the pivot.

Implementation-wise – what’s the best way to sort something like this? Having to explicitly handle the extraneous values results in a bunch more cases to address. I could probably assign values to the enumerations but there’s no guarantee that there wouldn’t be a different sorting order that would be useful in other cases. I’m not sure if it’s sufficient to simply assume that the list will be stripped of extra values before it’s sorted, since this is likely to cause bugs that are hard to find if the assumption is violated. I could throw ArgumentException when those values are used, but then I’d be adding enough cases that I might as well just sort them instead. About the best option I can come up with is to create a casting function to transform the enums into ints.

  • 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-27T14:19:39+00:00Added an answer on May 27, 2026 at 2:19 pm

    Usually, yes, the comparison needs to be consistent. (I’m not saying that the case for all algorithms out there, but it is for qsort for instance, and you should really stick with that.)

    What you can do to make your case simpler is just to consider that all the uninteresting values are equal, and that they are all either smaller than A or greater than C.

    That way, they’ll get packed at the top or the bottom of the results, and your comparison function shouldn’t be too complex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have a list(array, ect) of objects that have a static values.
I have a list of objects that have two int properties. The list is
I have a list of objects that I want to transform into another list
I have a list of custom objects that I am loading into an ActivityList
I have an ArrayList of objects that I need to sort in two different
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have 2 List objects: List<int> lst1 = new List<int>(); List<int> lst2 = new
I have List where myObj has it own list of objects called example mySubObj.
I have a list of custom objects List and I would like to update
I have a list of objects called Activity: class Activity { public Date activityDate;

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.