From 78c84dfec60e5766df37007a72e265c0fd80de41 Mon Sep 17 00:00:00 2001 From: krahets Date: Wed, 3 May 2023 22:58:48 +0800 Subject: [PATCH] Fix counting_sort.c --- codes/c/chapter_sorting/counting_sort.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/c/chapter_sorting/counting_sort.c b/codes/c/chapter_sorting/counting_sort.c index dea63303c..73ba54f0a 100644 --- a/codes/c/chapter_sorting/counting_sort.c +++ b/codes/c/chapter_sorting/counting_sort.c @@ -18,7 +18,7 @@ void countingSortNaive(int nums[], int size) { } // 2. 统计各数字的出现次数 // counter[num] 代表 num 的出现次数 - int *counter = malloc(sizeof(int) * size); + int *counter = malloc(sizeof(int) * m); for (int i = 0; i < size; i++) { counter[nums[i]]++; } @@ -43,7 +43,7 @@ void countingSort(int nums[], int size) { } // 2. 统计各数字的出现次数 // counter[num] 代表 num 的出现次数 - int *counter = malloc(sizeof(int) * size); + int *counter = malloc(sizeof(int) * m); for (int i = 0; i < size; i++) { counter[nums[i]]++; }