Common sorting algorithms-fast sorting (C language + VC6.0 platform) and vc6.0 Algorithm
Quick sorting in classic sorting algorithms is efficient, but its implementation is relatively difficult to understand.
# Include <stdio. h>
Int partition (int num [], int low, int high) // use the key as the benchmark to list the "high" and "low" columns, the data in the "high" part is larger than the key, and the data in the "low" part is smaller than the key.
{
Int left, right, key;
Left = low; right = high; key = num [low];
While (left <right)
{
While (left <right & num [right]> = key)
Right --;
Num [left] = num [right];
While (left <right & num [left] <= key)
Left ++;
Num [right] = num [left];
}
Num [left] = key;
Return left;
}
Void quick_sort (int num [], int low, int high) // recursive quick sorting
{
If (low
{
Int pos = partition (num, low, high );
Quick_sort (num, low, pos-1 );
Quick_sort (num, pos + 1, high );
}
}
Int main ()
{
Int data [10] = {32, 33 };
Int I;
For (I = 0; I <10; I ++)
Printf ("% d", data [I]);
Printf ("\ n ");
Quick_sort (data, 0, 9 );
For (I = 0; I <10; I ++)
Printf ("% d", data [I]);
Printf ("\ n ");
}