Advertisement
niske

Selection

Nov 13th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. public static void selection(Dete[] niz) {
  2. for(int i = 0; i < niz.length - 1; i++) {
  3. Dete min = niz[i];
  4. int idxmin = i;
  5.  
  6. for (int j = i+1; j < niz.length; j++) {
  7. if (niz[j].compareTo(min) < 0) {
  8. min = niz[j];
  9. idxmin = j;
  10. }
  11. }
  12. swap(niz, i, idxmin);
  13. }
  14. }
  15. private static void swap(Dete[] niz, int a, int b) {
  16. Dete temp = niz[a];
  17. niz[a] = niz[b];
  18. niz[b] = temp;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement