Add sorce code blocks of C to the docs.

This commit is contained in:
krahets
2023-02-11 18:22:27 +08:00
parent d3ea84ba97
commit d1e1d76162
18 changed files with 78 additions and 206 deletions
+2 -37
View File
@@ -86,23 +86,7 @@ comments: true
=== "C"
```c title="bubble_sort.c"
/* 冒泡排序 */
void bubbleSort(int nums[], int size) {
// 外循环:待排序元素数量为 n-1, n-2, ..., 1
for (int i = 0; i < size - 1; i++)
{
// 内循环:冒泡操作
for (int j = 0; j < size - 1 - i; j++)
{
if (nums[j] > nums[j + 1])
{
int temp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = temp;
}
}
}
}
[class]{}-[func]{bubbleSort}
```
=== "C#"
@@ -180,26 +164,7 @@ comments: true
=== "C"
```c title="bubble_sort.c"
/* 冒泡排序 */
void bubbleSortWithFlag(int nums[], int size) {
// 外循环:待排序元素数量为 n-1, n-2, ..., 1
for (int i = 0; i < size - 1; i++)
{
bool flag = false;
// 内循环:冒泡操作
for (int j = 0; j < size - 1 - i; j++)
{
if (nums[j] > nums[j + 1])
{
int temp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = temp;
flag = true;
}
}
if(!flag) break;
}
}
[class]{}-[func]{bubbleSortWithFlag}
```
=== "C#"