I think ive got the idea now, and also how would i trace this program? like show each step of the way until it ends? How can i change the code below to output a trace.
Code:
#include <stdio.h>
#define SIZE 10
int main()
{
int a[ SIZE ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
int i, pass, hold;
printf( "Data items in original order\n" );
for ( i = 0; i <= SIZE - 1; i++ )
printf( "%4d", a[ i ] );
for ( pass = 1; pass <= SIZE - 1; pass++ )
for( i = 0; i <= SIZE - 2; i++ )
printf( "%d %d ", a[ i ], hold );
if ( a[ i ] > a[ i + 1 ] ) {
hold = a[ i ];
a[ i ] = a[ i + 1 ];
a[ i + 1 ] = hold;
}
printf( "\nData items in ascending order\n" );
for ( i = 0; i <= SIZE - 1; i++ )
printf( "%4d", a[ i ] );
printf( "\n" );
return 0;
}