Guest User

Untitled

a guest
Dec 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public static int[] selectionSort(int ... numbers) {
  2. int pos, value;
  3. int[] result = numbers.clone();
  4. for (int i = 0; i < result.length - 1; i++) {
  5. value = result[i];
  6. pos = i;
  7. for (int j = i + 1; j < result.length; j++) {
  8. if (result[j] < value) {
  9. value = result[j];
  10. pos = j;
  11. }
  12. }
  13. result[pos] = result[i];
  14. result[i] = value;
  15. }
  16. return result;
  17. }
  18.  
  19. public static int[] selectionSortWorse(int ... numbers) {
  20. int pos, value;
  21. int[] result = numbers.clone();
  22. for (int i = 0; i < result.length - 1; i++) {
  23. pos = i;
  24. for (int j = i + 1; j < result.length; j++) {
  25. if (result[j] < result[pos]) {
  26. pos = j;
  27. }
  28. }
  29. value = result[pos];
  30. result[pos] = result[i];
  31. result[i] = value;
  32. }
  33. return result;
  34. }
Add Comment
Please, Sign In to add comment