#include
#include
#include
#include
#include
#include
#include
using namespace std;
void bubblesort(int a[],int n)//注意:定义函数的时候要写明数据类型,所以要int a【】,即引用a这个数组类型的数据。
{
int t;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (a[j] > a[j + 1])
{
t = a[j + 1];
a[j + 1] = a[j];
a[j] = t;
}
}
}
}
void print(int a[], int n)
{
for (int i = 0; i < n; i++)
cout << a[i];
}
int main()
{
int a[9] = { 6,2,8,7,3,1,5,4,4 };
int n = sizeof(a)/sizeof(a[0]);//计算数组长度的方法。
cout << n << endl;
bubblesort(a, n);//注意:数组名就相当于数组的首地址,在调用函数(计算也属于其中)时只用写数组名即可,不用数组框。
print(a, n);
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交