Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package materi;
- /**
- *
- * @author Dwi Kusumayani
- */
- public class quicksort {
- static void quickSort (int a[], int bawah, int atas){
- // lo adalah index bawah, hi adalah index atas
- // dari bagian array yang akan di urutkan
- int i=bawah, j=atas, h;
- int pivot=a[bawah];
- // pembagian
- do{
- while (a[i]<pivot) i++;
- while (a[j]>pivot) j--;
- if (i<=j)
- {
- h=a[i]; a[i]=a[j]; a[j]=h;//tukar
- i++; j--;
- }
- } while (i<=j);
- // pengurutan
- if (bawah<j) quickSort(a, bawah, j);
- if (i<atas) quickSort(a, i, atas);
- }
- public static void main(String[] args) {
- int tabInt[]={24,17,18,15,22,26, 13, 21, 16, 28};
- int i,n=10;
- for(i=0;i<n;i++){
- System.out.print(tabInt[i]+ " ");
- }
- System.out.print("\n");
- quickSort(tabInt,0,n-1);
- for(i=0;i<n;i++){
- System.out.print(tabInt[i]+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement