mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
47 lines
685 B
Markdown
47 lines
685 B
Markdown
|
# 6-2 冒泡排序
|
|||
|
|
|||
|
输入n(1<=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
|
|||
|
```
|
|||
|
|