Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Shell {
- public static void shell(int[] a) {
- int increment = a.length / 2;
- while (increment > 0) {
- for (int i = increment; i < a.length; i++) {
- int j = i;
- int temp = a[i];
- while (j >= increment && a[j - increment] > temp) {
- a[j] = a[j - increment];
- j = j - increment;
- }
- a[j] = temp;
- }
- if (increment == 2) {
- increment = 1;
- } else {
- increment *= (5.0 / 11);
- }
- }
- }
- public static void main(String[] args) {
- int[] x = new int[]{3, 2, 1, 21, 32, 12, 10, 29, 8};
- System.out.println("Sebelum:");
- for (Integer i : x) {
- System.out.print(i.intValue() + " ");
- }
- System.out.println("");
- shell(x);
- System.out.println("Sesudah:");
- for (Integer i : x) {
- System.out.print(i.intValue() + " ");
- }
- System.out.println("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement