Advertisement
korobushk

SORTING

May 14th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public static void sort(int[] array) {
  2.  
  3. int n = 0;
  4. int startIndex = 0;
  5. int smallest2 = 0;
  6.  
  7. for (int i = 0; i < array.length; i++) {
  8. startIndex = i;
  9. int smallest = array[startIndex];
  10. System.out.println(Arrays.toString(array));
  11.  
  12. for (int j = startIndex; j < array.length; j++) {
  13.  
  14. if (array[startIndex] < smallest) {
  15. smallest = array[startIndex];
  16.  
  17. }
  18. if (array[startIndex] == smallest) {
  19. smallest2 = startIndex;
  20. }
  21.  
  22. startIndex++;
  23.  
  24. }
  25.  
  26. int helper = array[smallest2];
  27. array[smallest2] = array[i];
  28. array[i] = helper;
  29.  
  30. n++;
  31.  
  32. }
  33.  
  34. //en index mas chico hay q swapearlo x ??
  35. //swapearlo al primer index
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement