This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 28th, 2013  |  syntax: C++  |  size: 0.57 KB  |  views: 73  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data