View difference between Paste ID: c3yKEg2q and Ti7iS5Ux
SHOW: | | - or go back to the newest paste.
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-
		int bubble ( x, y );
27+
28
		if ( x > y ) {
29
			int f;
30
			f = x;
31
			x = y;
32
			y = f;
33
		}
34
	}
35
		
36
	system("PAUSE");
37
}