Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- using namespace std;
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int n;
- cin>>n;
- if (n==0)
- {
- return 0;
- }
- double *a = new double[n];
- for (int i=0; i<n; i++)
- {
- cin>>a[i];
- }
- if (n==1)
- {
- cout<<a[0];
- return 0;
- }
- int bubble1Pos = 0, bubble2Pos = 1;
- while(bubble2Pos < n)
- {
- if (bubble1Pos < 0)
- {
- bubble1Pos++;
- bubble2Pos++;
- continue;
- }
- if (a[bubble1Pos] <= a[bubble2Pos])
- {
- bubble1Pos++;
- bubble2Pos++;
- }
- else
- {
- swap(a[bubble1Pos], a[bubble2Pos]);
- bubble1Pos--;
- bubble2Pos--;
- }
- }
- for (int i=0; i<n; i++)
- {
- cout << a[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement