mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 18:00:18 +08:00
Fine tune the C codes.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
add_executable(bubble_sort bubble_sort.c)
|
||||
add_executable(bucket_sort bucket_sort.c)
|
||||
add_executable(insertion_sort insertion_sort.c)
|
||||
add_executable(quick_sort quick_sort.c)
|
||||
add_executable(counting_sort counting_sort.c)
|
||||
add_executable(radix_sort radix_sort.c)
|
||||
add_executable(merge_sort merge_sort.c)
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* File: bucket_sort.c
|
||||
* Created Time: 2023-03-27
|
||||
* Author: Reanon (793584285@qq.com)
|
||||
*/
|
||||
|
||||
#include "../include/include.h"
|
||||
|
||||
/* 冒泡排序 */
|
||||
void bucketSort(double nums[], int size) {
|
||||
// 初始化 k = n/2 个桶,预期向每个桶分配 2 个元素
|
||||
int k = size / 2;
|
||||
// 1. 将数组元素分配到各个桶中
|
||||
// 输入数据范围 [0, 1),使用 num * k 映射到索引范围 [0, k-1]
|
||||
// 将 num 添加进桶 i
|
||||
|
||||
// 2. 对各个桶执行排序
|
||||
|
||||
// 使用内置切片排序函数,也可以替换成其他排序算法
|
||||
|
||||
// 3. 遍历桶合并结果
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
// 设输入数据为浮点数,范围为 [0, 1)
|
||||
double nums[] = {0.49, 0.96, 0.82, 0.09, 0.57, 0.43, 0.91, 0.75, 0.15, 0.37};
|
||||
int size = sizeof(nums) / sizeof(double);
|
||||
bucketSort(nums, size);
|
||||
|
||||
printf("桶排序完成后 nums = ");
|
||||
printArray(nums, size);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user