1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00
202401-programming-assignments/【实践课外】14.指针2/6-2 冒泡排序.md

47 lines
685 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 6-2 冒泡排序
输入n1<=n<=10个整数将它们从小到大排序后输出要求编写函数bubble()实现冒泡排序算法。
### 函数接口定义:
```c++
void bubble (int a[ ], int n);
```
其中 a为数组n为数据个数。
### 裁判测试程序样例:
```c++
#include <stdio.h>
void bubble (int a[ ], int n);
int main(void)
{
int n, a[10];
int i;
scanf("%d", &n);
for (i=0; i<n;i++)
scanf("%d",&a[i]);
bubble(a,n);
for (i=0; i<n; i++)
printf("%d ",a[i]);
printf("\n");
return 0;
}
/* 请在这里填写答案 */
```
### 输入样例:
```in
8
7 3 66 3 -5 22 -77 2
```
### 输出样例:
```out
-77 -5 2 3 3 7 22 66
```