# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
void mySort ( int arr[ ] , int len)
{
for ( int i = 0 ; i < len; i++ )
{
int min = i;
for ( int j = i+ 1 ; j < len; j++ )
{
if ( arr[ min] > arr[ j] )
{
min = j;
}
}
if ( i!= min)
{
int temp = arr[ i] ;
arr[ i] = arr[ min] ;
arr[ min] = temp;
}
}
}
void printArray ( int arr[ ] , int len)
{
for ( int i = 0 ; i < len; i++ )
{
printf ( "%s\n" , arr[ i] ) ;
}
}
void test01 ( )
{
int arr[ ] = { 3 , 5 , 1 , 2 , 4 } ;
int len = sizeof ( arr) / sizeof ( int ) ;
mySort ( arr, len) ;
printArray ( arr, len) ;
}
void selectSort ( char * arr[ ] , int len)
{
for ( int i = 0 ; i < len; i++ )
{
int max = i;
for ( int j = i+ 1 ; j < len; j++ )
{
if ( strcmp ( arr[ max] , arr[ j] ) == - 1 )
{
max = j;
}
}
if ( i!= max)
{
char * temp = arr[ i] ;
arr[ i] = arr[ max] ;
arr[ max] = temp;
}
}
}
void printArray2 ( char * * arr, int len)
{
for ( int i = 0 ; i < len; i++ )
{
printf ( "%s\n" , arr[ i] ) ;
}
}
void test02 ( )
{
char * pArr[ ] = { "aaa" , "bbb" , "ccc" , "ddd" , "fff" , "eee" } ;
int len = sizeof ( pArr) / sizeof ( char * ) ;
selectSort ( pArr, len) ;
printArray2 ( pArr, len) ;
}
int main ( )
{
test02 ( ) ;
system ( "pause" ) ;
return EXIT_SUCCESS;
}