Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int n;
  4. int s[100];
  5. int read_data()
  6. {
  7. cout << "n =";
  8. cin >> n;
  9. for(int i = 1; i<=n; i++)
  10. {
  11. cout << "S[" << i << "] = ";
  12. cin >> s[i];
  13. }
  14. }
  15.  
  16. int bubble()
  17. {
  18. int gata = 0;
  19. while(gata != 1)
  20. {
  21. for(int i = n; i>=1; i--)
  22. {
  23. if(s[i] > s[i-1])
  24. {
  25. swap(s[i], s[i-1]);
  26. gata = 0;
  27. break;
  28. }
  29. }
  30. gata = 1;
  31. }
  32. }
  33. int print_data()
  34. {
  35. cout << "Sortate: ";
  36. for(int i = 1; i<=n; i++)
  37. {
  38. cout << " " << s[i];
  39. }
  40. }
  41. int main()
  42. {
  43. read_data();
  44. bubble();
  45. print_data();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement