1.Quick_sort
int a[7]; //input sequence
void main()
{
Quicksort(0,6);
}
Quicksort(int f, int l)
{
if f>=l then
{
return;
}
int X = a[f];
int i = f;
int j = l;
while i < j do
{
while a[j] >= X do
{
j = j-1;
}
a[i] = a[j];
while a[i] <= X do
{
i = i+1;
}
a[i] = a[j];
}
Quicksort(f, j-1);
Quicksort(j+1, l);
}
//============================
2.Straight_selection_sort
int a[7]; //input sequence
void main()
{
straight_selection_sort();
}
straight_selection_sort()
{
int i, j;
int x;
for( i = 0 ; i < 6 ; i ++)
{
for( j = i+1 ; j < 7 ; j++)
{
if( a[i] > a[j] )
{
x = a[i];
a[i] = a[j];
a[j] = x;
}
}
}
}
沒有留言:
張貼留言