Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package materi;
  7.  
  8. /**
  9.  *
  10.  * @author Dwi Kusumayani
  11.  */
  12. public class quicksort {
  13.     static void quickSort (int a[], int bawah, int atas){
  14.     //  lo adalah index bawah, hi adalah index atas
  15.     //  dari bagian array yang akan di urutkan
  16.         int i=bawah, j=atas, h;
  17.         int pivot=a[bawah];
  18.  
  19.     //  pembagian
  20.         do{
  21.             while (a[i]<pivot) i++;
  22.             while (a[j]>pivot) j--;
  23.             if (i<=j)
  24.             {
  25.                 h=a[i]; a[i]=a[j]; a[j]=h;//tukar
  26.                 i++; j--;
  27.             }
  28.         } while (i<=j);
  29.  
  30.     //  pengurutan
  31.         if (bawah<j) quickSort(a, bawah, j);
  32.         if (i<atas) quickSort(a, i, atas);
  33.     }
  34.  
  35.    
  36.     public static void main(String[] args) {
  37.         int tabInt[]={24,17,18,15,22,26, 13, 21, 16, 28};
  38.         int i,n=10;
  39.        
  40.             for(i=0;i<n;i++){
  41.                 System.out.print(tabInt[i]+ " ");
  42.            }
  43.             System.out.print("\n");
  44.         quickSort(tabInt,0,n-1);
  45.        
  46.         for(i=0;i<n;i++){
  47.             System.out.print(tabInt[i]+" ");
  48.         }
  49.  
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement