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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:42:19+00:00 2026-06-01T10:42:19+00:00

I have recently been working to better my understanding of sorting algorithms and their

  • 0

I have recently been working to better my understanding of sorting algorithms and their relationship to different types of input. Currently, I’m working on a Student Management program where each student has three parameters: Last Name, GPA, and User ID (String, double, int). They are each stored in a Student class with those three parameters, and there are DOZENS of students (a key feature of the program is to input, remove, and update students).

My question is: using the major sorting algorithms (mergesort, quicksort, etc.), what is the best way to sort my list of students by each parameter? For instance, what is the best way to perform a mergesort to sort the list by GPA? Or to use quicksort to sort the list by last name?

Essentially my question boils down to…I can sort these objects if they didn’t have three parameters (writing a mergesort to sort 100 numbers is very easy for me). How do I manage the other two parameters and make sure they’re accessible after the sort?

  • 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-06-01T10:42:20+00:00Added an answer on June 1, 2026 at 10:42 am

    The way this is done in Java is to use different Comparators. Then you say:

    Collections.sort(list, new NameComparator());
    

    Or

    Collections.sort(list, new GpaComparator());
    

    These comparators use different fields to define the order between two elements.

    For example, Name Comparator might be:

    class NameComparator implements Comparator< Student> {
        @Override public int compare(Student left, Student right) {
            return left.getName().compareTo(right.getName());
        }
    }
    

    And GpaComparator might be

    class GpaComparator implements Comparator< Student> {
        @Override public int compare(Student left, Student right) {
            if (left.getGpa() < right.getGpa()) {
                return -1;
           } else if (left.getGpa() > right.getGpa()) {
                return 1;
           } else {
               return 0;
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been working with a COM+ component that processes an input XML
I have recently been doing a bit of investigation into the different types of
I have recently been working on implementing an ajax based file uploader for my
I have recently been working on a Pastebin script (for fun) and I've come
I have only recently been introduced to curl and am working on a certain
Recently I've been working on some embedded devices, where we have some structs and
I have been working on Eclipse recently. I am fairly new to java programming,
I have been working with databases recently and before that I was developing standalone
I have been working on a Java game and I recently wanted to see
I have a stored procedure that has been working just fine, but I recently

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.