Advertisement
sst311212

bubble sort

Dec 13th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void swap(int &a,int &b)
  7. {
  8.      int temp;
  9.      temp = b;
  10.      b = a;
  11.      a = temp;
  12. }
  13.  
  14. int main()
  15. {
  16.     int array[]={7,1,5,9,2};
  17.    
  18.     for (int i=0;i<5;i++){
  19.         for (int j=i+1;j<5;j++){
  20.             if (array[i] > array[j]){
  21.                 swap(array[i],array[j]);
  22.             }
  23.         }
  24.     cout<<array[i]<<" ";
  25.     }
  26.     cout<<endl;
  27.     system("PAUSE");
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement