// This program puts values into an array, sorts the values into // ascending order, and prints the resulting array. #include #include void bubbleSort(int * const, const int); main() { const int arraySize = 10; int a[arraySize] = {2, 6, 4, 8, 10, 12, 89, 68, 45, 37}; cout << "Data items in original order" << endl; for (int i = 0; i < arraySize; i++) cout << setw(4) << a[i]; bubbleSort(a, arraySize); // sort the array cout << endl << "Data items in ascending order" << endl; for (i = 0; i < arraySize; i++) cout << setw(4) << a[i]; cout << endl; return 0; } void bubbleSort(int * const array, const int size) { void swap(int * const, int * const); for (int pass = 1; pass < size; pass++) for (int j = 0; j < size - 1; j++) if (array[j] > array[j + 1]) swap(&array[j], &array[j + 1]); } void swap(int * const element1Ptr, int * const element2Ptr) { int temp = *element1Ptr; *element1Ptr = *element2Ptr; *element2Ptr = temp; }