Advertisement
yoeri

SelectionSort

May 24th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. public int[] SelectionSort(int[] nums)
  2. {
  3. int endOfArray = nums.Length - 1;
  4. int smallestNbr;
  5. int nextNbr;
  6.  
  7. for (int currentIndex = 0; currentIndex < endOfArray; currentIndex++)
  8. {
  9. smallestNbr = nums[currentIndex];
  10. for (int searchIndex = currentIndex + 1; searchIndex < endOfArray; searchIndex++)
  11. {
  12. nextNbr = nums[searchIndex];
  13. if(nextNbr < smallestNbr)
  14. {
  15. swap(nums, nums[currentIndex], nums[searchIndex]);
  16. }
  17. }
  18. }
  19. return nums;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement