Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /**
  2. * Created by degget on 26.06.2017.
  3. */
  4.  
  5. import java.util.Arrays;
  6.  
  7. public class ShellSort {
  8.  
  9. public static void shell(int[] a) {
  10. int increment = a.length / 2;
  11. while (increment > 0) {
  12. for (int i = increment; i < a.length; i++) {
  13. int j = i;
  14. int temp = a[i];
  15. while (j >= increment && a[j - increment] > temp) {
  16. a[j] = a[j - increment];
  17. j = j - increment;
  18. }
  19. a[j] = temp;
  20. }
  21. if (increment == 2) {
  22. increment = 1;
  23. } else {
  24. increment *= (5.0 / 11);
  25. }
  26. }
  27. }
  28.  
  29. public static void main(String[] args) {
  30.  
  31.  
  32. int[] myArr = new int[]{1, 23, 3, 8, 2, 4, 4, 26, 32, 48, 54, 1024, 575, 368, 10, 11};
  33.  
  34. System.out.println("Array till sort");
  35.  
  36. for (int i = 0; i < myArr.length; i++) {
  37.  
  38. System.out.print(myArr[i] + " ");
  39. }
  40. System.out.println("");
  41.  
  42. System.out.println("Array after sort");
  43.  
  44. shell(myArr);
  45.  
  46. for (int j = 0; j < myArr.length; j++) {
  47.  
  48. System.out.print(myArr[j] + " ");
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement