Skip to content

Commit 9397a7a

Browse files
committed
Merge branch 'main' of https://github.com/Mdr-C-Tutorial/C
2 parents e756199 + 261554f commit 9397a7a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/教程/正文/语法和标准库/18_算法库.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ void qsort(void *ptr, size_t count, size_t size, int (*compare)(const void *, co
1818
1919
其中:
2020
21-
+ `ptr` 是指向要排序的数组的指针;
22-
+ `count` 是数组中元素的个数;
23-
+ `size` 是数组中每个元素的大小;
24-
+ `compare` 是一个比较函数,用于确定数组中元素的顺序。
21+
- `ptr` 是指向要排序的数组的指针;
22+
- `count` 是数组中元素的个数;
23+
- `size` 是数组中每个元素的大小;
24+
- `compare` 是一个比较函数,用于确定数组中元素的顺序。
2525
2626
### 比较函数
2727
@@ -63,27 +63,27 @@ int compare(const void *a, const void *b) {
6363
#include <limits.h>
6464
#include <stdio.h>
6565
#include <stdlib.h>
66-
66+
6767
int compare_ints(const void* a, const void* b)
6868
{
6969
int arg1 = *(const int*)a;
7070
int arg2 = *(const int*)b;
71-
71+
7272
if (arg1 < arg2) return -1;
7373
if (arg1 > arg2) return 1;
7474
return 0;
7575
}
76-
76+
7777
int main(void)
7878
{
7979
int ints[] = {-2, 99, 0, -743, 2, INT_MIN, 4};
8080
size_t size = sizeof ints / sizeof ints[0];
81-
81+
8282
qsort(ints, size, sizeof(int), compare_ints);
83-
83+
8484
for (size_t i = 0; i < size; i++)
8585
printf("%d ", ints[i]);
86-
86+
8787
printf("\n");
8888
}
8989
```
@@ -185,4 +185,4 @@ void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int
185185
186186
其中:
187187
188-
+ `key` 是指向要搜索的键值的指针;
188+
- `key` 是指向要搜索的键值的指针;

0 commit comments

Comments
 (0)