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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:53:56+00:00 2026-06-17T09:53:56+00:00

Please take a look at this snippet code from and implementation of quicksort, it’s

  • 0

Please take a look at this snippet code from and implementation of quicksort, it’s from the book Data Structures and Problem Solving Using Java :

    int i, j;

    for(i = low, j = high -1;;){

        while(array[++i].compareTo(pivot) < 0)
            ;
        while(pivot.compareTo(array[--j]) < 0)
            ;
        if(i >= j)
            break;
        swapReferences(array, i, j);
    }

I’m having a bit of trouble understanding how this works. From my understanding the for loop just declares the starting point and doesn’t contain any rules on when to finish the for loop; that’s handled by the if statement, is that correct?
Also, without the brackets I’m not clear about the while loops. the semi-colon and lack of indentation suggested they’re not nested. But there’s no actual code within the loops.
Am I correct in saying each while is separate, one compares lower values to the pivot and one compares higher values, swapping when each of the while loops criteria are met. As the i is incremented and j is decremented every time the for loop carries on with the process until the criteria for the if statement are met at which point it breaks from the for loop?
Is this correct?

EDIT: Updated code to reflect exactly what was in the book.

  • 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-17T09:53:57+00:00Added an answer on June 17, 2026 at 9:53 am

    Your analysis is correct. The while loops do their work implicitly, with ++i and --j. It could be rewritten for more clarity as

    do i++; while (array[i] < pivot);
    do j--; while (pivot < array[j]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please take a look at this code: template<class T> class A { class base
Please take a look at this piece of code. I'm allocating one byte for
Please take a look at this below line of code in JSF <h:inputText id=name
Please take a look at THIS page. Please feed in some random data and
Please take a look at the code snippet below. I want the 2nd MongoDB
Please take a look at this piece of code I came up with. abstract
Please take a look at this simple code: http://jsfiddle.net/kerp3/ The box has an inner
please take a look at the following code snippet: #include <stdio.h> int main ()
Please take a look at this XML code: <TableLayout android:id=@+id/tableLayout1 android:layout_width=fill_parent android:layout_height=fill_parent android:padding=10dip android:isScrollContainer=true
Please take a look at this code (thanks to user budwiser), it matches a

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.