Solved

Can anyone explain line 39, 40, 41, 42, 43?

Posted on 2002-05-15
3
194 Views
Last Modified: 2010-03-31
import java.awt.*;
import javax.swing.*;

public class Quicksort extends JApplet
{
String output="";
//37,2,6,4,89,8,10,12,68,45};//
public void init ()
{ // initialize
int a[] = {37,2,6,4,89,8,10,12,68,45};

output+= "The initial array is: \t";
for (int i=0; i<a.length; i++)
output+= a[i] +" ";

// call recursive function
quickSort (a, 0, (a.length -1) );

output+= "\nThe sorted array is: \t";
for (int i=0; i<a.length; i++)
output+= a[i] +" ";

JTextArea outputArea = new JTextArea (80, 15);
JScrollPane scroller = new JScrollPane (outputArea);
Container c = getContentPane();
c.add(scroller);
outputArea.setText (output);
} // end init method

public void quickSort(int b[], int st, int end)
{ int finalPos;

// base case
if (end-st+1 <= 1) return; // don't partition anymore

// main recursive subroutine
else // continue to partition and quickSort the subarrays
{
finalPos = partition (b, st, end);  //??
if ( ((finalPos-1)-st +1) >1 )      //?
quickSort(b, st, finalPos-1);       //?
if ( end-(finalPos+1)+1 >1 )        //?
quickSort (b, finalPos+1, end);     //?
}

} // end quickSort method definition
0
Comment
Question by:brett605
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
ID: 7011843
I don't know how familiar you are with recursion and quick sort, so if you wanted more detail, please ask.

The basic idea of a quick sort is to take a list of items and partition it into 2 pieces. There must be some swapping to ensure that each portion contains the "correct" elements. Having achieved that (which would happen here with the partition method, for which the code is not listed), you then proceed to check if the two "half" lists contain more than one item or not. If they do, they you call quicksort for the "half" list. (Half is in quotes, because there is actually no requirement that the two lists be the same size).

So again, there are two potentially big and confusing topics here: recursion and quicksort. Recursion occurs when a routine calls itself. Quicksort is a particular sorting algorithm (usually defined recursively) that is very fast (in terms of number of swaps).

0
 
LVL 35

Expert Comment

by:girionis
ID: 8749750
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to imladris

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running JavaFX on JDeveloper 12C 1 78
ejb wildfly example 2 74
add projects t working set in maven 2 44
Notify sent to other threads in Java 9 43
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question