diff --git a/codes/c/chapter_sorting/radix_sort.c b/codes/c/chapter_sorting/radix_sort.c index 31b940dc3..dbc747541 100644 --- a/codes/c/chapter_sorting/radix_sort.c +++ b/codes/c/chapter_sorting/radix_sort.c @@ -13,7 +13,7 @@ int digit(int num, int exp) { } /* 计数排序(根据 nums 第 k 位排序) */ -void countSort(int nums[], int size, int exp) { +void countingSort(int nums[], int size, int exp) { // 十进制的各位数字范围为 0~9 ,因此需要长度为 10 的桶 int *bucket = (int *) malloc((sizeof(int) * 10)); // 借助桶来统计 0~9 各数字的出现次数 @@ -57,7 +57,7 @@ void radixSort(int nums[], int size) { // k = 2 -> exp = 10 // k = 3 -> exp = 100 // 即 exp = 10^(k-1) - countSort(nums, size, exp); + countingSort(nums, size, exp); } int main() { diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp index 60f38e3f4..1bbccc48c 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp @@ -27,7 +27,7 @@ public: /* 析构方法 */ ~LinkedListDeque() { - // 释放内存 + // 遍历链表删除结点,释放内存 DoublyListNode *pre, *cur = front; while (cur != nullptr) { pre = cur; diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp index 5ecb4565c..1e89a2c28 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp @@ -20,8 +20,8 @@ public: } ~LinkedListQueue() { - delete front; - delete rear; + // 遍历链表删除结点,释放内存 + freeMemoryLinkedList(front); } /* 获取队列的长度 */ diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp index c7e76da2e..1fd06be08 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_stack.cpp @@ -19,6 +19,7 @@ public: } ~LinkedListStack() { + // 遍历链表删除结点,释放内存 freeMemoryLinkedList(stackTop); } diff --git a/codes/dart/chapter_sorting/radix_sort.dart b/codes/dart/chapter_sorting/radix_sort.dart index c25b3804b..5ef2fc478 100644 --- a/codes/dart/chapter_sorting/radix_sort.dart +++ b/codes/dart/chapter_sorting/radix_sort.dart @@ -11,7 +11,7 @@ int digit(int num, int exp) { } /* 计数排序(根据 nums 第 k 位排序) */ -void countSort(List nums, int exp) { +void countingSort(List nums, int exp) { // 十进制的各位数字范围为 0~9 ,因此需要长度为 10 的桶 List bucket = List.filled(10, 0); int n = nums.length; @@ -49,7 +49,7 @@ void radixSort(List nums) { // k = 2 -> exp = 10 // k = 3 -> exp = 100 // 即 exp = 10^(k-1) - countSort(nums, exp); + countingSort(nums, exp); } /* Driver Code */ diff --git a/codes/go/chapter_sorting/radix_sort.go b/codes/go/chapter_sorting/radix_sort.go index e44ea868c..30756f132 100644 --- a/codes/go/chapter_sorting/radix_sort.go +++ b/codes/go/chapter_sorting/radix_sort.go @@ -13,7 +13,7 @@ func digit(num, exp int) int { } /* 计数排序(根据 nums 第 k 位排序) */ -func countSort(nums []int, exp int) { +func countingSort(nums []int, exp int) { // 十进制的各位数字范围为 0~9 ,因此需要长度为 10 的桶 bucket := make([]int, 10) n := len(nums) @@ -56,6 +56,6 @@ func radixSort(nums []int) { // k = 2 -> exp = 10 // k = 3 -> exp = 100 // 即 exp = 10^(k-1) - countSort(nums, exp) + countingSort(nums, exp) } } diff --git a/codes/java/chapter_sorting/radix_sort.java b/codes/java/chapter_sorting/radix_sort.java index 473218327..90f5b619e 100644 --- a/codes/java/chapter_sorting/radix_sort.java +++ b/codes/java/chapter_sorting/radix_sort.java @@ -16,7 +16,7 @@ public class radix_sort { } /* 计数排序(根据 nums 第 k 位排序) */ - static void countSort(int[] nums, int exp) { + static void countingSort(int[] nums, int exp) { // 十进制的各位数字范围为 0~9 ,因此需要长度为 10 的桶 int[] bucket = new int[10]; int n = nums.length; @@ -55,7 +55,7 @@ public class radix_sort { // k = 2 -> exp = 10 // k = 3 -> exp = 100 // 即 exp = 10^(k-1) - countSort(nums, exp); + countingSort(nums, exp); } public static void main(String[] args) { diff --git a/codes/swift/chapter_sorting/radix_sort.swift b/codes/swift/chapter_sorting/radix_sort.swift index 99b3c003f..e1281c468 100644 --- a/codes/swift/chapter_sorting/radix_sort.swift +++ b/codes/swift/chapter_sorting/radix_sort.swift @@ -11,7 +11,7 @@ func digit(num: Int, exp: Int) -> Int { } /* 计数排序(根据 nums 第 k 位排序) */ -func countSort(nums: inout [Int], exp: Int) { +func countingSort(nums: inout [Int], exp: Int) { // 十进制的各位数字范围为 0~9 ,因此需要长度为 10 的桶 var bucket = Array(repeating: 0, count: 10) let n = nums.count @@ -54,7 +54,7 @@ func radixSort(nums: inout [Int]) { // k = 2 -> exp = 10 // k = 3 -> exp = 100 // 即 exp = 10^(k-1) - countSort(nums: &nums, exp: exp) + countingSort(nums: &nums, exp: exp) } } diff --git a/codes/zig/chapter_sorting/radix_sort.zig b/codes/zig/chapter_sorting/radix_sort.zig index c9fc2cc9b..9f266d1ff 100644 --- a/codes/zig/chapter_sorting/radix_sort.zig +++ b/codes/zig/chapter_sorting/radix_sort.zig @@ -12,7 +12,7 @@ fn digit(num: i32, exp: i32) i32 { } // 计数排序(根据 nums 第 k 位排序) -fn countSort(nums: []i32, exp: i32) !void { +fn countingSort(nums: []i32, exp: i32) !void { // 十进制的各位数字范围为 0~9 ,因此需要长度为 10 的桶 var mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); // defer mem_arena.deinit(); @@ -62,7 +62,7 @@ fn radixSort(nums: []i32) !void { // k = 2 -> exp = 10 // k = 3 -> exp = 100 // 即 exp = 10^(k-1) - try countSort(nums, exp); + try countingSort(nums, exp); } }