Using a bubble sort, I need to show the contents of the Grades array after each pass, but I haven't had any luck with figuring out the correct printf statement to get it to print after each pass... any suggestions???? I thought it would need to be printf("%d", the variable )... I thought it would be one of the following variables, but none would give me the correct answer)
Grades[ k ] = Grades[ k + 1 ];
Grades[ k + 1 ] = hold;
Thanks!
Here's what I have so far :>
/* Show the contents of the Grades array after each pass. */
#include <stdio.h>
#define SIZE 5
int main()
{
int Grades[ SIZE ] = { 86, 93, 87, 99, 78 };
int k, pass, hold;
printf( "Data items in original order\n" );
for ( k = 0; k <= SIZE - 1; k++ )
printf( "%4d", Grades[k] );
for ( pass = 1; pass <= SIZE - 1; pass++ ) /* passes */
for ( k = 0; k <= SIZE - 2; k++ ) /* one pass */
if ( Grades[ k ] > Grades[ k + 1 ] ) /* one comparison */
{
hold = Grades[ k ]; /* one swap */
Grades[ k ] = Grades[ k + 1 ];
Grades[ k + 1 ] = hold;
}
printf( "\nData items in ascending order\n" );
for ( k = 0; k <= SIZE - 1; k++ )
printf( "%4d", Grades[ k ] );
printf( "\n" );
return 0;
}