// Example 1-10 Bubble sort #include using namespace std; void print(int a[], int size); void bubble_sort (int a[], int size); void swap (int& a, int& b); int main() { int array[] = { 7,9,6,2,5,3 }; int size = sizeof(array) / sizeof(int); bubble_sort(array,size); print(array,size); return 0; } void print (int a[], int size) { int i; for (i = 0; i < size; i++) { cout << a[i] << '\t'; } cout << endl; } void bubble_sort (int a[], int size) { bool swapOccurred; do { swapOccurred = false; for (int i = 0; i < size-1; i++) { if (a[i] > a[i+1]) { swap(a[i],a[i+1]); swapOccurred = true; } } } while (swapOccurred); } void swap (int& a, int& b) { int temp; temp = a; a = b; b = temp; }