Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4. int[] intArray = {80, 57, 121, 26, 93, 172, 107, 36, 88, 64, 67, 124, 7, 20, 53, 154, 196, 29, 82, 34, 142, 110,
  5. 159, 17, 192, 46, 65, 115, 162, 184, 168, 102, 35, 19, 23, 70, 163, 166, 187, 129, 90, 193, 143, 167,
  6. 119, 95, 89, 58, 178, 71};
  7. insertionSort(intArray);
  8. }
  9.  
  10. public static void insertionSort(int[] data) {
  11. int n = data.length;
  12. for (int k = 1; k < n; k++) {
  13. int cur = data[k];
  14. int j = k;
  15. while (j > 0 && data[j - 1] > cur) {
  16. data[j] = data[j - 1];
  17. j--;
  18. }
  19. data[j] = cur;
  20. }
  21.  
  22. String result = "";
  23. for (int i : data)
  24. result += "" + i + " ";
  25. System.out.println(result);
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement