using namespace std;
void (int *sortList, int number)
{
int i = 0;
for (; i <= number; i++)
{
cout<<sortList[i]<<" ";
}
cout<<endl;
}
static int improveQsort(int *sortList, int firstNum, int lastNum)
{
int tmpNum;
tmpNum = sortList[firstNum];
while ( firstNum < lastNum )
{
while ( firstNum < lastNum && sortList[lastNum] > tmpNum )
{
lastNum--;
}
if ( firstNum < lastNum )
{
sortList[firstNum++] = sortList[lastNum];
}
while ( firstNum < lastNum && sortList[firstNum] <= tmpNum )
{
firstNum++;
}
if ( firstNum < lastNum )
{
sortList[lastNum--] = sortList[firstNum];
}
}
sortList[firstNum] = tmpNum;
return firstNum;
}
static void quickSort(int *sortList, int firstNum, int lastNum)
{
int current = 0;
if ( firstNum < lastNum ){
current = improveQsort(sortList, firstNum, lastNum);
quickSort(sortList, firstNum, current-1);
quickSort(sortList,current+1,lastNum);
}
}
int main (int argc, char *argv[])
{
int sortList[10] = {5, 3, 7, 4, 1, 9, 8, 6, 2, 3};
int number = 10;
quickSort(sortList,0,number-1);
showResult(sortList,number-1);
return 0;
}
近期评论