Advertisement
SergeyPGUTI

6.3.8

Nov 21st, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void BubbleSort(int A[],int n)
  6. {
  7.     int temp;
  8.     for (int i=1;i<=n;i++)
  9.     {
  10.         for (int j=1;j<n-i;j++)
  11.         {
  12.             if (A[j]>A[j+1])
  13.             {
  14.                 temp=A[j];
  15.                 A[j]=A[j+1];
  16.                 A[j+1]=temp;
  17.             }
  18.         }
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     int n;
  25.     cin>>n;
  26.     int * A=new int [n+1];
  27.     for (int i=1;i<=n;i++)
  28.     {
  29.         cin>>A[i];
  30.     }
  31.     BubbleSort(A,n);
  32.  
  33.     for (int i=1;i<=n;i++)
  34.     {
  35.         cout<<A[i]<<" ";
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement