Advertisement
HelloDearSir

Untitled

Feb 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. int c;
  6. int b;
  7. int a[10];
  8. void print(void);
  9. int mini;
  10. int z;
  11. int j;
  12. fstream Array;
  13.  
  14. void main(void)
  15. {
  16. Array.open("sort.txt", ios::in);
  17. if (Array.fail())
  18. {
  19. cout << " This file d " << endl << endl;
  20. }
  21.  
  22. else {
  23.  
  24.  
  25. for (int j = 0; j < 10; j++)
  26. {
  27. mini = a[j];
  28. z = j;
  29. for (int i = j + 1; i < 10; i++)
  30. {
  31.  
  32. if (a[i] < mini)
  33. {
  34. mini = a[i];
  35. z = i;
  36. }
  37.  
  38.  
  39. }
  40. a[z] = a[j];
  41. a[j] = mini;
  42. }
  43. Array.close();
  44. print();
  45. _getch();
  46. }
  47. }
  48.  
  49.  
  50. //bubble sort
  51.  
  52.  
  53.  
  54.  
  55.  
  56. void print(void)
  57. {
  58. for (int i = 0; i < 10; i++)
  59. {
  60. cout << "a[" << i << " ] =" << a[i] << endl;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement