This commit is contained in:
krahets
2024-03-31 03:53:04 +08:00
parent 87af663929
commit c23e576da4
68 changed files with 2139 additions and 22 deletions

View File

@ -271,6 +271,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="bubble_sort.rb"
[class]{}-[func]{bubble_sort}
```
=== "Zig"
```zig title="bubble_sort.zig"
@ -574,6 +580,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="bubble_sort.rb"
[class]{}-[func]{bubble_sort_with_flag}
```
=== "Zig"
```zig title="bubble_sort.zig"

View File

@ -345,8 +345,8 @@ comments: true
int k = size / 2;
float **buckets = calloc(k, sizeof(float *));
for (int i = 0; i < k; i++) {
// 每个桶最多可以分配 k 个元素
buckets[i] = calloc(ARRAY_SIZE, sizeof(float));
// 每个桶最多可以分配 size 个元素
buckets[i] = calloc(size, sizeof(float));
}
// 1. 将数组元素分配到各个桶中
@ -359,7 +359,7 @@ comments: true
j++;
}
float temp = nums[i];
while (j < ARRAY_SIZE && buckets[bucket_idx][j] > 0) {
while (j < size && buckets[bucket_idx][j] > 0) {
swap(&temp, &buckets[bucket_idx][j]);
j++;
}
@ -368,12 +368,12 @@ comments: true
// 2. 对各个桶执行排序
for (int i = 0; i < k; i++) {
qsort(buckets[i], ARRAY_SIZE, sizeof(float), compare_float);
qsort(buckets[i], size, sizeof(float), compare_float);
}
// 3. 遍历桶合并结果
for (int i = 0, j = 0; j < k; j++) {
for (int l = 0; l < ARRAY_SIZE; l++) {
for (int l = 0; l < size; l++) {
if (buckets[j][l] > 0) {
nums[i++] = buckets[j][l];
}
@ -421,6 +421,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="bucket_sort.rb"
[class]{}-[func]{bucket_sort}
```
=== "Zig"
```zig title="bucket_sort.zig"

View File

@ -345,6 +345,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="counting_sort.rb"
[class]{}-[func]{counting_sort_naive}
```
=== "Zig"
```zig title="counting_sort.zig"
@ -845,6 +851,12 @@ $$
}
```
=== "Ruby"
```ruby title="counting_sort.rb"
[class]{}-[func]{counting_sort}
```
=== "Zig"
```zig title="counting_sort.zig"

View File

@ -572,6 +572,14 @@ comments: true
}
```
=== "Ruby"
```ruby title="heap_sort.rb"
[class]{}-[func]{sift_down}
[class]{}-[func]{heap_sort}
```
=== "Zig"
```zig title="heap_sort.zig"

View File

@ -250,6 +250,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="insertion_sort.rb"
[class]{}-[func]{insertion_sort}
```
=== "Zig"
```zig title="insertion_sort.zig"

View File

@ -625,6 +625,14 @@ comments: true
}
```
=== "Ruby"
```ruby title="merge_sort.rb"
[class]{}-[func]{merge}
[class]{}-[func]{merge_sort}
```
=== "Zig"
```zig title="merge_sort.zig"

View File

@ -351,6 +351,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="quick_sort.rb"
[class]{QuickSort}-[func]{partition}
```
=== "Zig"
```zig title="quick_sort.zig"
@ -609,6 +615,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="quick_sort.rb"
[class]{QuickSort}-[func]{quick_sort}
```
=== "Zig"
```zig title="quick_sort.zig"
@ -1073,6 +1085,14 @@ comments: true
}
```
=== "Ruby"
```ruby title="quick_sort.rb"
[class]{QuickSortMedian}-[func]{median_three}
[class]{QuickSortMedian}-[func]{partition}
```
=== "Zig"
```zig title="quick_sort.zig"
@ -1364,6 +1384,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="quick_sort.rb"
[class]{QuickSortTailCall}-[func]{quick_sort}
```
=== "Zig"
```zig title="quick_sort.zig"

View File

@ -672,6 +672,16 @@ $$
}
```
=== "Ruby"
```ruby title="radix_sort.rb"
[class]{}-[func]{digit}
[class]{}-[func]{counting_sort_digit}
[class]{}-[func]{radix_sort}
```
=== "Zig"
```zig title="radix_sort.zig"

View File

@ -300,6 +300,12 @@ comments: true
}
```
=== "Ruby"
```ruby title="selection_sort.rb"
[class]{}-[func]{selection_sort}
```
=== "Zig"
```zig title="selection_sort.zig"