Code:
Void quick_sort (int * list, int the begin, int the end)
{
Int temp=list (begin);
Int tempEnd=end;
If (end> The begin)
{
While (begin
While ((begin
List [begin]=list [end];
While ((begin
Begin++;
The list [end]=list (begin);
}
The list (begin)=temp;
Quick_sort (list, 0, the begin - 1);
Quick_sort (list, the begin + 1, tempEnd);
}
}
Then because of the quick sort requires recursion, can not directly in the function of timing, so I write again a function to call the quick sort function:
Void take_quick (int * list, int the begin, int the end)
{
Clock_t start=clock ();
Quick_sort (list, the begin and end);
Double now=double ((clock () - start))/CLOCKS_PER_SEC;
Cout<" Quick time: "& lt;
In order to be fair, of course, the other two sorting algorithm I also used this method, call methods are the same, but the result above,,,, is this why???????
CodePudding user response:
This,,, knowledge blind area, touches me,CodePudding user response:
You are using recursion to realize fast row, try non-recursive implementationCodePudding user response:
Upstairs said recursion is one of the reasons, the calling function need cost is larger,40 number but the key reason is that, you can't see the value of fast row, depends on the speed, you have to at least 400000 data... To 400000 data, then compare the time-consuming and feel the difference...