Advertisement
SVXX

Selection Sort (My Algo)

Jan 17th, 2012
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. void SelSort(int a[], int size)
  6. {
  7. int i, j, temp, min;
  8. for(i = 1; i <= size; i++)
  9. {
  10. min = a[i];
  11. for(j = i+1; j <= size; j++)
  12. {
  13. if(min > a[j])
  14. {
  15. temp = min;
  16. min = a[j];
  17. a[j] = temp;
  18. }
  19. }
  20. a[i] = min;
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. int i, j, a[50], size;
  27. cout << "Enter the size : ";
  28. cin >> size;
  29. for(i = 1; i <= size; i++)
  30. {
  31. cout << "\nEnter element " << i << " : ";
  32. cin >> a[i];
  33. }
  34. SelSort(a, size);
  35. cout << "\nSorted array : ";
  36. for(i = 1; i <= size; i++)
  37. {
  38. cout << a[i] << "\t";
  39. }
  40. getch();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement