mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
feat: Revised the book (#978)
* Sync recent changes to the revised Word. * Revised the preface chapter * Revised the introduction chapter * Revised the computation complexity chapter * Revised the chapter data structure * Revised the chapter array and linked list * Revised the chapter stack and queue * Revised the chapter hashing * Revised the chapter tree * Revised the chapter heap * Revised the chapter graph * Revised the chapter searching * Reivised the sorting chapter * Revised the divide and conquer chapter * Revised the chapter backtacking * Revised the DP chapter * Revised the greedy chapter * Revised the appendix chapter * Revised the preface chapter doubly * Revised the figures
This commit is contained in:
@ -17,7 +17,7 @@ const QuickSort = struct {
|
||||
|
||||
// 哨兵划分
|
||||
pub fn partition(nums: []i32, left: usize, right: usize) usize {
|
||||
// 以 nums[left] 作为基准数
|
||||
// 以 nums[left] 为基准数
|
||||
var i = left;
|
||||
var j = right;
|
||||
while (i < j) {
|
||||
@ -70,7 +70,7 @@ const QuickSortMedian = struct {
|
||||
var med = medianThree(nums, left, (left + right) / 2, right);
|
||||
// 将中位数交换至数组最左端
|
||||
swap(nums, left, med);
|
||||
// 以 nums[left] 作为基准数
|
||||
// 以 nums[left] 为基准数
|
||||
var i = left;
|
||||
var j = right;
|
||||
while (i < j) {
|
||||
@ -107,7 +107,7 @@ const QuickSortTailCall = struct {
|
||||
|
||||
// 哨兵划分
|
||||
pub fn partition(nums: []i32, left: usize, right: usize) usize {
|
||||
// 以 nums[left] 作为基准数
|
||||
// 以 nums[left] 为基准数
|
||||
var i = left;
|
||||
var j = right;
|
||||
while (i < j) {
|
||||
@ -127,7 +127,7 @@ const QuickSortTailCall = struct {
|
||||
while (left < right) {
|
||||
// 哨兵划分操作
|
||||
var pivot = partition(nums, left, right);
|
||||
// 对两个子数组中较短的那个执行快排
|
||||
// 对两个子数组中较短的那个执行快速排序
|
||||
if (pivot - left < right - pivot) {
|
||||
quickSort(nums, left, pivot - 1); // 递归排序左子数组
|
||||
left = pivot + 1; // 剩余未排序区间为 [pivot + 1, right]
|
||||
|
||||
@ -13,7 +13,7 @@ fn digit(num: i32, exp: i32) i32 {
|
||||
|
||||
// 计数排序(根据 nums 第 k 位排序)
|
||||
fn countingSortDigit(nums: []i32, exp: i32) !void {
|
||||
// 十进制的位范围为 0~9 ,因此需要长度为 10 的桶
|
||||
// 十进制的位范围为 0~9 ,因此需要长度为 10 的桶数组
|
||||
var mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
// defer mem_arena.deinit();
|
||||
const mem_allocator = mem_arena.allocator();
|
||||
|
||||
Reference in New Issue
Block a user