SHARE
TWEET

Untitled

a guest Nov 19th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @(#)Tugas1.java
  3.  *
  4.  *
  5.  * @author
  6.  * @version 1.00 2015/4/20
  7.  */
  8.  
  9.  
  10. class ExchangeSort
  11. {
  12.     private long [] data;
  13.     private int jumItem;
  14.     public ExchangeSort(int max)
  15.     {
  16.       data = new long[max];
  17.       jumItem = 0;
  18.    
  19.     }
  20.      
  21.     public void tambah(long nilai)
  22.     {
  23.       data[jumItem] = nilai;
  24.       jumItem++;
  25.    
  26.     }
  27.     public void cetak ()
  28.     {
  29.       for (int j=0; j<jumItem; j++)
  30.         System.out.print(data[j] + " ");
  31.       System.out.println(" ");
  32.      
  33.     }
  34.     public void exchange_sort()
  35.     {
  36.       int i, j;
  37.       for (i=0; i<jumItem-1; i++)
  38.       {
  39.        
  40.         for(j = (i+1); j<jumItem; j++)
  41.         {
  42.        
  43.           if (data[i] < data [j])
  44.           tukar(i,j);
  45.          
  46.         }
  47.         System.out.print("Hasil langkah ke " +(i+1)+ " :");
  48.         cetak();
  49.         System.out.println();
  50.        
  51.      
  52.       }
  53.    
  54.    
  55.     }
  56.     private void tukar (int a, int b)
  57.     {
  58.    
  59.      
  60.       long temp = data[a];
  61.       data[a]= data[b];
  62.       data[b]= temp;
  63.      
  64.     }
  65. }
  66.  
  67.  
  68. class Tugas1
  69. {
  70.   public static void main(String[]args)
  71.   {
  72.    
  73.     int ukuran = 100;
  74.     ExchangeSort DeretAngka;
  75.     DeretAngka = new ExchangeSort(ukuran);
  76.     DeretAngka.tambah(84);
  77.     DeretAngka.tambah(69);
  78.     DeretAngka.tambah(76);
  79.     DeretAngka.tambah(86);
  80.     DeretAngka.tambah(94);
  81.     DeretAngka.tambah(91);
  82.     System.out.print("Data Awal :");
  83.     DeretAngka.cetak();
  84.     System.out.println();
  85.     DeretAngka.exchange_sort();
  86.     System.out.print("Data Akhir :");
  87.     DeretAngka.cetak();
  88.     System.out.println();
  89.   }
  90.  
  91.  
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top