- 论坛徽章:
- 1
|
回复 23# crazyhadoop
让你见笑了^_^。我写了个非递归的,怎么比递归的还慢?- void x_qsort(int *array, int low, int high)
- {
- if (low < high)
- {
- queue<int> q;
- q.push(low);
- q.push(high);
- while(!q.empty())
- {
- int low = q.front();
- q.pop();
- int high = q.front();
- q.pop();
- if (low < high)
- {
- int p = partition(array, low, high);
- q.push(low);
- q.push(p - 1);
- q.push(p + 1);
- q.push(high);
- }
- }
- }
- }
复制代码 [root@bogon _ping]# ./t
inpput size:1000000
input times:5
t1 = 1.17seconds
t2 = 0.83seconds
two arrays is the same.diff = -340000
t1 = 1.22seconds
t2 = 1.02seconds
two arrays is the same.diff = -200000
t1 = 1.29seconds
t2 = 1.1seconds
two arrays is the same.diff = -190000
t1 = 1.37seconds
t2 = 1.25seconds
two arrays is the same.diff = -120000
|
|