Leonard_M

Bubble Sort - INT Array

Mar 28th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int v[400], val, x, n;
  5. int main()
  6. {
  7.     int ok,i,aux;
  8.     cout<<"n: "; cin>>n;
  9.     for(int i=1; i<=n; i++) cin>>v[i];
  10.     do
  11.     {
  12.         ok=1;
  13.         for(i=1; i<=n-1; i++)
  14.             if(v[i]>v[i+1])
  15.             {
  16.                 ok=0;
  17.                 aux=v[i];
  18.                 v[i]=v[i+1];
  19.                 v[i+1]=aux;
  20.             }
  21.     }
  22.     while(ok!=1);
  23.     for(int i=1; i<=n; i++) cout<<v[i]<<" ";
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment