Brick99

DMOJ Bubble sort

May 22nd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <utility>
  4. using namespace std;
  5.  
  6. int n;
  7. int A[21];
  8.  
  9. void sortt()
  10. {
  11.     int br=n-1;
  12.  
  13.     while (br>0)
  14.     {
  15.         if (br==n-1)
  16.         {
  17.             for (int i=0;i<n;i++) cout<<A[i]<<" ";
  18.             cout<<endl;
  19.         }
  20.         for (int i=0;i<br;i++)
  21.         {
  22.             for (int j=i+1;j<br+1;j++)
  23.             {
  24.                 if (A[i]>A[j])
  25.                 {
  26.                     int prenos=A[i];
  27.                     A[i]=A[j];
  28.                     A[j]=prenos;
  29.                     i++;
  30.  
  31.                     for (int k=0;k<n;k++) cout<<A[k]<<" ";
  32.                     cout<<endl;
  33.                 }
  34.                 else i++;
  35.             }
  36.         }
  37.         br--;
  38.     }
  39. }
  40.  
  41. int main()
  42. {
  43.     cin>>n;
  44.  
  45.     for (int i=0;i<n;i++) cin>>A[i];
  46.  
  47.     sortt();
  48.     return 0;
  49. }
Add Comment
Please, Sign In to add comment