排序算法
常考排序
快速排序
void qs(List<int> nums, int left, int right) {
if (left >= right) {
return;
}
int start = left;
int end = right;
int pivot = nums[end];
while (start <= end) {
while (start <= end && nums[start] < pivot) {
start++;
}
while (start <= end && nums[end] > pivot) {
end--;
}
if (start <= end) {
int temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
start++;
end--;
}
}
qs(nums, left, end);
qs(nums, start, right);
}归并排序
堆排序
用数组表示的完美二叉树 complete binary tree
完美二叉树 VS 其他二叉树


参考
练习
Last updated