冒泡排序(c++)

#include <iostream>
using namespace std;
int main()
{
 int a[11];
 int i, j, t;
 cout << "input 10 numbers: " << endl;
 for (i = 1; i <= 10;i++)
 {
  cin >> a[i];
  cout << endl;
 }
 for (j = 1; j <= 9;j++)//共进行n-1轮比较  9轮
 for (i = 1; i <= 10 - j;i++)//在每轮中要进行10-j次两两比较
 if (a[i]>a[i+1])
 {
  t = a[i]; a[i] = a[i + 1]; a[i + 1] = t;//交换两个数的位置,使小数上浮
 }
 cout << "the sorted numbers: " << endl;//输出10个数
 for (i = 1; i < 11;i++)
 {
  cout << a[i] <<"  "<< endl;
 }
 return 0;
}

原文地址:https://www.cnblogs.com/rong123/p/7788938.html