Guest User

Bubble sort (working)

a guest
Apr 30th, 2011
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int array[10] = {4,3,11,9,7,54,12,35,31,1};
  7.    
  8.     cout << "The array's original order: ";
  9.     for(int ac = 0;ac<9;ac++)
  10.     {
  11.             cout << array[ac] << ", ";
  12.     }
  13.    
  14.     cout << endl;
  15.    
  16.     //##Bubble sort##
  17.     int swapper;
  18.    
  19.     for (int bsc=1;bsc<11;bsc++)
  20.     {
  21.          for (int sc=0;sc<8;sc++)
  22.          {
  23.              if(array[sc] > array[sc+1])
  24.              {
  25.                           swapper = array[sc];
  26.                           array[sc] = array[sc+1];
  27.                           array[sc+1] = swapper;
  28.              }
  29.          }  
  30.     }
  31.     //##Sorted##
  32.    
  33.     cout << "The array sorted          : ";
  34.     for(int ac = 0;ac<9;ac++)
  35.     {
  36.             cout << array[ac] << ", ";
  37.     }
  38.     cout << endl;
  39.    
  40.  system("pause");
  41.  return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment