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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:03:24+00:00 2026-05-15T05:03:24+00:00

I have question about my code which does the Hoare Partition Method. Here is

  • 0

I have question about my code which does the Hoare Partition Method.

Here is the pseudo-code: (please correct something if it’s incorrect)

HOARE-PARTITION ( A, p, r)
 1 x ← A[ p]
 2 i ← p−1
 3 j ← r +1
 4 while TRUE
 5        do repeat j ← j − 1
 6        until A[ j ] ≤ x

 7        do repeat i ← i + 1
 8        until A[i] ≥ x

 9        if i < j
10             then exchange A[i] ↔ A[ j ]
11             else return j

And my code:

public class Hoare {
    public static  int partition(int a[],int p,int r) {
        int x = a[p];
        int i = p - 1;
        int j = r + 1;

        while (true) {    
            do
            {
                j = j - 1;
            } while(a[j] >= x);

            do
            {
                i = i + 1;
            } while(a[i] <= x);

            if (i < j) {
                int t = a[i];
                a[i] = a[j];
                a[j] = t;
            } else {    
                return j;
            }
        }        
    }

    public static void main(String[]args) {
        int a[] = {13, 19, 9, 5, 12, 8, 7, 4, 11, 2, 6, 21};
        partition(a, 0, a.length-1);
    }
}

And error is:

error: Class names, 'Hoare', are only accepted if annotation
processing is explicitly requested
1 error

Any ideas as to the cause?

  • 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-15T05:03:25+00:00Added an answer on May 15, 2026 at 5:03 am

    You seem to have translated:

    do repeat stmt
    until A[ j ] ≤ x;
    

    into

    do {
        stmt;
    } while (A[j] >= x);
    

    This is not correct. The comparison which is the opposite of ≤ would be >, not ≥. Therefore, your comparison when translating from “until” to “while” would use > such as while (A[j] > x);.

    The other errors in your possible homework are similar and I encourage you to think each translation through carefully on your own.

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

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer JQuery plugin uploadify will upload with a progress bar, and… May 15, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer You need to be careful of two things when doing… May 15, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer Sorry, Josh, I think what you've found here is a… May 15, 2026 at 5:22 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.