quicksort and priority_queue

Contributor:游客Mercy Type:代码 Date time:2016-05-24 21:05:25 Favorite:2 Score:0.5
返回上页 Report
请选择举报理由:




Collection Modify the typo
template <typename T>
void quickSort(int *a, int low, int high) {
if (low >= high) return;
int l = low, h = high;
int k = a[low];
while (l < h) {
while (l < h && !(a[h] < k)) h--;
if (l < h) a[l++] = a[h];
while (l < h && a[l] < k) l++;
if (l < h) a[h--] = a[l];
}
a[l] = k;
if (l > low) quickSort(a, low, l);
if (l+1 < high) quickSort(a, l+1, high);
}
int pq[MAX_N];
void push(int x) {
int now = ++length;
while (now > 1) {
if (x < pq[now/2]) {
pq[now] = pq[now/2];
now /= 2;
} else
break;
}
pq[now] = x;
}
int pop() {
int ret = pq[1];
int now = 1;
int x = pq[length--];
while (now * 2 <= length) {
int child = now * 2;
if (child + 1 <= length && pq[child+1] < pq[child]) child++;
if (pq[child] < x) {
pq[now] = pq[child];
now = child;
} else
break;
}
pq[now] = x;
return ret;
}
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
Hot degree:
Difficulty:
quality:
Description: the system according to the heat, the difficulty, the quality of automatic certification, the certification of the article will be involved in typing!

This paper typing ranking TOP20

登录后可见

用户更多文章推荐