void selectSort(char *data, int count)
{
int i, j, pos;
char temp;
for ( i = 0; i < count - 1; i++ )
{
pos = i;
temp = data[pos];
for ( j = i + 1; j < count; j++ )
if ( data[j] < temp )
{
pos = j;
temp = data[j];
}
data[pos] = data[i];
data[i] = temp;
printf("%d: [%s]\n", i+1, data);
}
}
void bubbleSort(char *data, int count)
{
int i,j;
int temp;
for ( j = count; j > 1; j-- )
{
for ( i = 0; i < j - 1; i++ )
if ( data[i+1] < data[i] )
{
temp = data[i+1];
data[i+1] = data[i];
data[i] = temp;
}
printf("%d: [%s]\n", count-j+1, data);
}
}
{
int i, j, pos;
char temp;
for ( i = 0; i < count - 1; i++ )
{
pos = i;
temp = data[pos];
for ( j = i + 1; j < count; j++ )
if ( data[j] < temp )
{
pos = j;
temp = data[j];
}
data[pos] = data[i];
data[i] = temp;
printf("%d: [%s]\n", i+1, data);
}
}
void bubbleSort(char *data, int count)
{
int i,j;
int temp;
for ( j = count; j > 1; j-- )
{
for ( i = 0; i < j - 1; i++ )
if ( data[i+1] < data[i] )
{
temp = data[i+1];
data[i+1] = data[i];
data[i] = temp;
}
printf("%d: [%s]\n", count-j+1, data);
}
}
全站熱搜
留言列表