How to implement QuickSort in Java?

QuickSort is a method which any array element to print Ascending order or Descending order.

QuickSort can used to Array partition in his array.

QuickSort also used  functions in Arrary elements. Then function also called function and used Recursion.

It is interesting Sorting methods.

Your QuickSort program is here.

Quick Sort

Quick Sort in Acsending Order ——–


package avi;
import java.util.Scanner;
public class Quicksort {

public static void main ( String [ ] args) {
int [ ]a={4,2,7,-9,6};
quicksort ( a , 0 , a.length-1 ) ;
for(int i=0; i<=a.length-1; i++)
System.out.print ( a[ i ] + " , " ) ;
System.out.println();

}

static void quicksort ( int [ ] a , int left , int right )
{
if ( left > right )
return;
int pivot = a [ left ] ;
int pos = left ;
int t ;
for( int i = left+1  i<= right ; i++)
{
if ( a[ i ] > pivot)
continue;
pos++ ;
t=a [pos] ;
a[ pos ] = a[ i ];
a[ i ] = t;
}
t = a[ left ] ;
a[ left ] = a[ pos ] ;
a[ pos ] = t ;
quicksort ( a , left , pos-1 ) ;
quicksort ( a , pos+1 , right ) ;

}
}

 

 

Leave a Reply