Advertisement
palmerstone

Selection Sort

Oct 30th, 2011
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7.  
  8. void SelectionSort(int ar[300], int n)
  9. {
  10. int a, b, c, d, i, j, min;
  11. for (i = 0; i < n; i++)
  12. {
  13. min = ar[i];
  14. for (j = i + 1; j < n; j++)
  15. {
  16. if (ar[j] < min)
  17. {
  18. d = j;
  19. min = ar[j];
  20. }
  21. }
  22. ar[d] = ar[i];
  23. ar[i] = min;
  24. }
  25. }
  26.  
  27. int main()
  28. {
  29. int t, i = 0, j, k, l, a, b, c, d, x, y, z, n, ar[300];
  30. char str[100];
  31.  
  32. freopen("numbers.txt", "r", stdin);
  33. for (; ;)
  34. {
  35. gets(str);
  36. if (feof(stdin)) break;
  37. ar[i++] = atoi(str);
  38. }
  39.  
  40. SelectionSort(ar, i);
  41. for (l = 0; l < i; l++) printf("%d\n", ar[l]);
  42.  
  43. return 0;
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement