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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:57:17+00:00 2026-06-09T15:57:17+00:00

I am trying to set up quick sort, and I want it to sort

  • 0

I am trying to set up quick sort, and I want it to sort an array of fractions.
Currently, it won’t properly sort fractions that have an equal value (e.g. 1/2 and 2/4)
1/2 would need to be before 2/4, yet it ends up completly random.

The code I’m using is this:

   public static void quicksort(Fraction[] f, int p, int r)
    {
        if (p < r)
        {
            int q = partition(f, p, r);
            quicksort(f, p, q - 1);
            quicksort(f, q + 1, r);
        }
    }

    public static int partition(Fraction[] f, int p, int r)
    {
        Fraction pivot = f[r];
        int i = p - 1;
        for (int j = p; j < r; j++)
        {
            if (f[j].Value < pivot.Value)
            {
                i++;
                Fraction wissel = f[i];
                f[i] = f[j];
                f[j] = wissel;
            }
            else
                if (f[j].Value < pivot.Value && f[j].Teller < pivot.Teller)
                {
                    i++;
                    Fraction wissel = f[i];
                    f[i] = f[j];
                    f[j] = wissel;
                }
        }
        Fraction wisselt = f[i + 1];
        f[i + 1] = f[r];
        f[r] = wisselt;
        return i + 1;

    }

Can anyone shed some light on how to do this?

EDIT: David Archer’s suggestion fixed it, thank you guys.

  • 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-09T15:57:19+00:00Added an answer on June 9, 2026 at 3:57 pm

    I’m not sure what Fraction class you are using but if you need to distinguish between 1/2 and 2/4 (which are equal in strict mathematical terms), I’d suggest creating your own comparison methods and using those instead of the built-in greater-than and less-than operators.

    bool IsLessThan(Fraction a, Fraction b)
    {
        // Your code here that results in 1/2 being less than 2/4
    }
    
    bool IsGreaterThan(Fraction a, Fraction b)
    {
        // Your code here that results in 2/4 being greater than 1/2
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up a quick PHP demo using the Youtube API that
Quick question. I am trying to set up a page that searches a database
Here's what I hope is a quick question... I am trying to set a
I have made a quick fiddle to outline my problem: http://jsfiddle.net/mYdxw/ I'm trying to
I have made a quick Jsbin: http://jsbin.com/ujabew/edit#javascript,html,live What i'm trying to achieve is to
I'm trying to set up the GWT framework. I'm following the quick start at:
I'm trying to build a quick overview that shows the upcoming calendar week. I
I'll explain what I'm trying to do real quick. I have a page where
Couple of quick questions. I have a DMX king USB lighting controller that I'm
Im trying to write a quick plugin that will load some AJAX content into

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.