Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. freopen("input.txt", "r", stdin);
  8. freopen("output.txt", "w", stdout);
  9.  
  10. int n;
  11. cin>>n;
  12. if (n==0)
  13. {
  14. return 0;
  15. }
  16. double *a = new double[n];
  17. for (int i=0; i<n; i++)
  18. {
  19. cin>>a[i];
  20. }
  21. if (n==1)
  22. {
  23. cout<<a[0];
  24. return 0;
  25. }
  26.  
  27. int bubble1Pos = 0, bubble2Pos = 1;
  28. while(bubble2Pos < n)
  29. {
  30. if (bubble1Pos < 0)
  31. {
  32. bubble1Pos++;
  33. bubble2Pos++;
  34. continue;
  35. }
  36. if (a[bubble1Pos] <= a[bubble2Pos])
  37. {
  38. bubble1Pos++;
  39. bubble2Pos++;
  40. }
  41. else
  42. {
  43. swap(a[bubble1Pos], a[bubble2Pos]);
  44. bubble1Pos--;
  45. bubble2Pos--;
  46. }
  47. }
  48. for (int i=0; i<n; i++)
  49. {
  50. cout << a[i] << " ";
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement