C++冒泡排序
#include<memory.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
void sort(int A[],int n)
{
for (int i = 1; i < n; i++)
{
for (int j = 0; j < i; j ++ )
{
if (A[j]>A[i])
{
int temp = A[i];
A[i] = A[j];
A[j] = temp;
}
}
}
for (int i = 0; i < n; i++)
{
cout << A[i] <<" ";
}
cout << "" << endl;
}
int main()
{
int A[] = { 9,8,7,6,5,4,3,2,1 };
int n = sizeof(A)/sizeof(A[0]);
cout << n << endl;
for (int i=0; i < n; i++)
{
cout << A[i] << "";
}
cout << "" << endl;
sort(A, n);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8bd2ef3f874e75796d2f022917a2d9d1.png)