-
Algoritma
Metode Shell Sort
1.
Jarak =
N
2.
Selama Jarak > 1 (kerjakan baris 3
sampai dengan 12)
3.
Jarak ß
Jarak/2
4.
Did_Swap ß
true
5.
Kerjakan baris 6 sampai dengan 12 selama
did_swap = true
6.
Did_Swap ß
false
7.
I ß
0
8.
Selama I < (N – Jarak ) kerjakan
baris 9 sampai dengan 12
9.
Jika (Data [i], Data [I + Jarak])
10.
Tukar(Data[i], Data [I + Jarak])
11.
Did_Swap ß
true
12.
I =
I + 1
SOURCE CODE SHELL SORT :
public
class ShellSort {
public void shellShort (int[] array) {
int jarak = array.length;
int i;
while (jarak>1){
jarak = jarak/2;
boolean did_swap = true;
while (did_swap){
did_swap = false;
i = 0;
while
(i
if
(array[i]>array[i+jarak]){
int tukar = array[i];
array[i] = array[i +
jarak];
array[i+jarak] = tukar;
did_swap = true;
}
i = i+1;
}
}
}
System.out.print("Data Setelah
Diurutkan : ");
for (int y = 0; y
System.out.print(array[y] + "
");
}
System.out.println("");
System.out.println("jumlah data :
" + array.length);
System.out.println("Big-O : "
+(Math.sqrt(Math.pow(3,2))));
}
}
0 komentar:
Posting Komentar