快速排序,模板
2022-05-08 21:07
views:
338
source:
Coat
void qs(int h[], int l, int r)
{
if (l >= r) return;
int x = h[l+r>>1], i = l - 1, j = r + 1;
while (i < j)
{
do i++; while (h[i] < x);
do j--; while (h[j] > x);
if (i < j) swap(h[i],h[j]);
}
if(l<j)
qs(h, l, j);
if (r > j);
qs(h, j+1, r);
}
Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.