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

  • Home
  • SEARCH
  • 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 225599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:25:46+00:00 2026-05-11T19:25:46+00:00

Have been scatching my head about this – and I reckon it’s simple but

  • 0

Have been scatching my head about this – and I reckon it’s simple but my geometry/algebra is pretty rubbish, and I can’t remember how to do this stuff from my school days!

EDITED:
I have a list of coordinates with people stood by them – I need an algorithm to order people from top left to bottom right in a list (array), and the second criteria demands that coordinates that are closer towards the top left origin take prescendance over all others – how would you do this?

The code should show the order as:

  1. Tom
  2. Harry
  3. Bob
  4. Dave

See diagram below:

alt text

  • 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-11T19:25:46+00:00Added an answer on May 11, 2026 at 7:25 pm

    From your ordering, it looks like you are putting y position at a higher priority than x position, so something like this would work when comparing two people:

    if (a.y > b.y)
    // a is before b
    else if (a.x < b.x)
    // a is before b
    else
    // b is before a
    

    edit for update
    This comparison still works with your new criteria. Y position is still has precedence over the X position. If the Y values are equal, the point closest to the top left corner would be the one with the smaller X value. If you want to make your object a comparator, implementing this as your comparator function would allow you to do ArrayList.sort() where negative means the first person is before the second:

    public int compareTo(person a, person b) {
        if (a.y == b.y)
           return a.x-b.x
        else
           return b.y-a.y
    }
    
    //compareTo(Tom, Harry) == -50 (tom is before harry)
    //compareTo(Tom, Bob) == -25 (tom is before bob)
    //compareTo(Dave, Bob) == 30 (dave is after bob)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been scratching my head for a while on this one. I dont
I have been searching for info on this to no avail. The context of
Have been studying the file system related classes of Adobe AIR 1.5, but so
I have been working on a web services related project for about the last
I have a table that looks like this for about ~30 students: StudentID Course*
For the past eight months or so, I have been banging my head on
I realize that this question has been asked and has been answered here but
I have been scratching my head trying to get Jquery to conditionally search and
Have been searching for this, I need to have a conditional statement in my
I have been searching everywhere for the following functionality in Lisp, and have gotten

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.