Advertisement
Guest User

Untitled

a guest
Mar 28th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //7.11
  2. /* Bubble sort algorithm - several passes through array - pairs elements compared
  3. If identical or in increasing order - leave as
  4. else swap
  5. 0 compare with 1, 1 compare with 2, etc
  6. 10 integers */
  7.  
  8. #include <iostream>
  9. #include <cstdlib>
  10.  
  11. using namespace std;
  12.  
  13. int bubble( int a, int b) {
  14.     int f;
  15.     f = a;
  16.     a = b;
  17.     b = f;
  18. }
  19.  
  20. int main () {
  21.  
  22.     int a[ 10 ] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
  23.  
  24.     for ( int i = 0; i <= 9; i++ ) {
  25.         int x = a[ i ];
  26.         int y = a[ i + 1];
  27.  
  28.         if ( x > y ) {
  29.             int f;
  30.             f = x;
  31.             x = y;
  32.             y = f;
  33.         }
  34.     }
  35.        
  36.     system("PAUSE");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement