Fix the deconstructor of linkedlist_queue.cpp
This commit is contained in:
parent
fcdc96e03d
commit
0840bc2043
@ -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() {
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
/* 析构方法 */
|
||||
~LinkedListDeque() {
|
||||
// 释放内存
|
||||
// 遍历链表删除结点,释放内存
|
||||
DoublyListNode *pre, *cur = front;
|
||||
while (cur != nullptr) {
|
||||
pre = cur;
|
||||
|
@ -20,8 +20,8 @@ public:
|
||||
}
|
||||
|
||||
~LinkedListQueue() {
|
||||
delete front;
|
||||
delete rear;
|
||||
// 遍历链表删除结点,释放内存
|
||||
freeMemoryLinkedList(front);
|
||||
}
|
||||
|
||||
/* 获取队列的长度 */
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
}
|
||||
|
||||
~LinkedListStack() {
|
||||
// 遍历链表删除结点,释放内存
|
||||
freeMemoryLinkedList(stackTop);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ int digit(int num, int exp) {
|
||||
}
|
||||
|
||||
/* 计数排序(根据 nums 第 k 位排序) */
|
||||
void countSort(List<int> nums, int exp) {
|
||||
void countingSort(List<int> nums, int exp) {
|
||||
// 十进制的各位数字范围为 0~9 ,因此需要长度为 10 的桶
|
||||
List<int> bucket = List<int>.filled(10, 0);
|
||||
int n = nums.length;
|
||||
@ -49,7 +49,7 @@ void radixSort(List<int> nums) {
|
||||
// k = 2 -> exp = 10
|
||||
// k = 3 -> exp = 100
|
||||
// 即 exp = 10^(k-1)
|
||||
countSort(nums, exp);
|
||||
countingSort(nums, exp);
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user