Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public static final int max = 10;
  2. int[] toSortArray = new int[max];
  3.  
  4. for(int i = 0; i < max; i++){
  5.  
  6. if (i == 0){
  7. i++;
  8. }
  9.  
  10. for(int j = 0; j < i; j++){
  11. if(toSortArray[i] < toSortArray[j]){
  12. int temp;
  13. temp = toSortArray[i];
  14. toSortArray[i] = toSortArray[j];
  15. toSortArray[j] = temp;
  16. }
  17. }
  18.  
  19. for (int i = 0; i < max; i++) {
  20. System.out.print(" | " + toSortArray[i]);
  21. }
  22.  
  23. public static void insertSort(int[] A){
  24. for(int i = 1; i < A.length; i++){
  25. int value = A[i];
  26. int j = i - 1;
  27. while(j >= 0 && A[j] > value){
  28. A[j + 1] = A[j];
  29. j = j - 1;
  30. }
  31. A[j + 1] = value;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement