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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:50:05+00:00 2026-05-31T07:50:05+00:00

I have a little problem with sorting out a list using an implementation of

  • 0

I have a little problem with sorting out a list using an implementation of IComparer.

public struct VAL
{
    public int i;
    public string s;
}

public struct INFO
{
    public string name;
    public VAL val;
    public string address;
}

public class ListSorter:IComparer<INFO>
{
    public enum SORT_TYPE{BYNAME, BYVAL,BYADDRESS};
    public int Compare(INFO i1, INFO i2)
        {
        switch(sortType)
        {
            case SORT_TYPE.BYNAME;
                return string.Compare(i1.name, i2.name);
            case SORT_TYPE.BYADDRESS:
                return string.Compare(i1.address, i2.address); 
            case SORT_TYPE.BYVAL:
            {
                ??????
            }
        }
    }   
}

The comparison function in the class ListSorter is an example of how I am comparing strings in the given INFO struct. But I don’t know how to sort the list based on the VAL struct information members

  • 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-31T07:50:07+00:00Added an answer on May 31, 2026 at 7:50 am

    Normally you would do something like:

    case SORT_TYPE.BYVAL:
    {
        int ret = i1.VAL.i.CompareTo(i2.VAL.i);
        if (ret != 0)
        {
            return ret;
        }
        return i1.VAL.s.CompareTo(i2.VAL.s);
    }
    

    You first compare the i and if they are equal you compare the s (or the opposite, the order must be selected by you).

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

Sidebar

Related Questions

have a little problem here: int IntegerTransformer::transformFrom(std::string string){ stream->clear(); std::cout<<string<<std::endl;; (*stream)<<string; int i; (*stream)>>i;
I have a little problem understanding the Java language public class PhonebookEntryList extends List<PhonebookEntry>
I have a little problem using jQuery and sorting a JSON array. What I'm
I have this little problem, that I cannot figure out which arguments to pass
I have a little problem with a query. I'm selecting data using the between
I have a little problem about using jQuery (I really do not know jQuery
i have little problem in using my application application having msaccess database if i
I have a little problem with converting a char string array to an unsigned
i have little problem with if { string nom; string ou; nom = 1;
I have a little problem, I am building a database from CSV files using

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.