#include "stdafx.h" #include <iostream> using namespace std; #define MAXARRAYSIZE 6 void swap ( int *pNum1, int *pNum2 ) { int temp; temp = *pNum1; *pNum1 = *pNum2; *pNum2 = temp; } void bubbleSort ( int values [], int size ) { int i; bool exchg = true; while ( exchg ) { exchg = false; for ( i = 0; i < ( size - 1 ); i++ ) { if ( values[i] > values[i + 1] ) { exchg = true; swap ( &values[i], &values[i + 1] ); } } } } void prntArray ( int *pValues, int size ) { int indx; for ( indx = 0; indx < size; indx++ ) cout << *( pValues + indx ) << " "; cout << endl; } int main() { int values [] = {10, 9, 8, 7, 6, 5}; prntArray (values, MAXARRAYSIZE); bubbleSort (values, MAXARRAYSIZE); prntArray (values, MAXARRAYSIZE); return 0; }How would we change prntArray to print out the message "ORIGINAL ARRAY" the first time and "SORTED ARRAY" the second time?
Is the sorting algorithm very efficient? Why or why not?
Can you think of a way to speed up the sorting algorithm?