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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:22:15+00:00 2026-05-31T10:22:15+00:00

Consider the following pseudo code: List<Person> People = new List<Person>(); int score; … foreach

  • 0

Consider the following pseudo code:

List<Person> People = new List<Person>();
int score;

...

foreach (Person p in People){

score = scoreFunc(p);

???

}

Question – how can I sort a list of Person objects by the score ?
In case you are wondering, I would not want to make the score a property of Person because it will be different for the same Person in different circumstances and is not logically a property of Person.

  • 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-31T10:22:16+00:00Added an answer on May 31, 2026 at 10:22 am

    Sorting happens using a delegate/class that can compare two persons – there is no mandate that you need to compare them using single attribute. For example

    People.Sort((p1,p2)=>scoreFunc(p1)-scoreFunc(p2));
    

    EDIT:

    If you wish to sort the whole list by a score then this will be the only way (you may change the sorting algorithm but comparison would not change because score is the sorting key). Now above would probably compute the score for some persons multiple time – so one of the optimization could be to cache the person score. For example, scoreFunc can check in the cache (dictionary) to see if score has been already computed or not.

    Further optimizations can happen based on your actual requirements and scoring function implementation. For example, assume that you have 10000 persons and you are probably interested in top 20. Assume that person’s age and educational qualifications contributes bulk of the score while there are 20 other attributes that do minor contribution. So you can do multi-pass sorting – the first pass may use a score based on only two factors to determine say top 500 persons and then you apply detailed scoring to do get actual top 20.

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

Sidebar

Related Questions

Consider following code: My problem is: 1) I can't seem to cast the errors
Consider the following pseudo code: def g_user(): while True: yield read_user_input() def g_socket(): while
Consider the following two methods, written in pseudo code, that fetches a complex data
Consider the following pseudo-tsql table a { field1 int, field2 int NULL } table
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)
What am I doing wrong here ? /* * Consider the following pseudo code
Consider following script (it's total nonsense in pseudo-language): if (Request.hostMatch(asfasfasf.com) && someString.existsIn(new String[] {brr,
Consider following code: typedef SomeType type_t[2]; SomeType * arr1 = new type_t; //new or
Consider the following pseudo code : template<class... T> struct worker : unique<T...>::type...{}; struct x{};
Consider following scenario: I have RESTful URL /articles that returns list of articles user

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.