Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //7.11
- /* Bubble sort algorithm - several passes through array - pairs elements compared
- If identical or in increasing order - leave as
- else swap
- 0 compare with 1, 1 compare with 2, etc
- 10 integers */
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int bubble( int a, int b) {
- int f;
- f = a;
- a = b;
- b = f;
- }
- int main () {
- int a[ 10 ] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
- for ( int i = 0; i <= 9; i++ ) {
- int x = a[ i ];
- int y = a[ i + 1];
- if ( x > y ) {
- int f;
- f = x;
- x = y;
- y = f;
- }
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement