Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package b;
- public class Shell {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int[] a = new int[] {1,3,5,2,4};
- int n = a.length;
- //phase = 0
- int step = n / 2;
- //phase = 1
- while (step > 0) {
- //phase = 2
- int i = 0;
- //phase = 3
- while (i < (n - step)) {
- //phase = 4
- int j = i;
- //phase = 5
- while (j >= 0 && a[j] > a[j + step]) {
- //phase = 6 (можно разбить на несколько фаз, но чего-то как-то не охота)
- int t = a[j];
- a[j] = a[j + step];
- a[j + step] = t;
- //phase = 7
- j--;
- }
- //phase = 8
- i++;
- }
- //phase = 9
- step /= 2;
- }
- for (int k = 0; k < n; k++) {
- System.out.print(a[k] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement