Advertisement
Guest User

SelectionSort

a guest
Jan 23rd, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1.  
  2. public class SelectionSort {
  3.  
  4. public SelectionSort(int[] a)
  5. {
  6.  
  7. //this.a = a;
  8. //shallow copy
  9. //OR THIS?
  10. //deep copy
  11. this.a = new int[a.length];
  12. for(int i = 0; i < a.length; i++)
  13. this.a[i] = a[i];
  14.  
  15. }
  16.  
  17. public int sort()
  18. {
  19. for (int i = 0; i < a.length; i++)
  20. {
  21. int min = ArrayUtil.minimumPosition(i, a);
  22. ArrayUtil.swap(min, i, a);
  23. swaps++;
  24. }
  25. return swaps;
  26. }
  27.  
  28.  
  29. public int[] getArray()
  30. {
  31. return a;
  32. }
  33.  
  34. public int getSwaps()
  35. {
  36. return swaps;
  37. }
  38.  
  39. private int swaps;
  40. private int[] a;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement