#include <iostream>
void SelectSort( int array[], int len );
int main( void )
{
int array[] = { 42, 20, 17, 13, 28, 14, 23, 15 };
int len;
len= sizeof( array )/ sizeof( array[ 0 ] );
SelectSort( array, len );
return 0;
}
void SelectSort( int array[], int len )
{
int temp;
int min;
for( int i= 0; i< len; i++ )
{
min= array[ i ];
for( int j= i+ 1; j< len; j++ )
{
if( array[ j ]< min )
{
temp= min;
min= array[ j ];
array[ j ]=temp;
}
array[ i ]= min;
}
for( int k= 0; k< len; k++ )
{
std::cout<< array[ k ]<< " ";
}
std::cout<< "\n";
}
}
The result:
42 20 17 13 28 14 23 15
-----------------------
13 42 20 17 28 14 23 15
13 14 42 20 28 17 23 15
13 14 15 42 28 20 23 17
13 14 15 17 42 28 23 20
13 14 15 17 20 42 28 23
13 14 15 17 20 23 42 28
13 14 15 17 20 23 28 42
13 14 15 17 20 23 28 42
0 Comment:
Post a Comment