#include <iostream>
using namespace std;
void MySort(int IntegerArray[], int length)
{
// 初始化中间变量
int InterVariables = 0;
for (int i = 0; i < length; i++)
{
// 对第i个数进行i次比较,依次前移
for (int j = i; j > 0; j--)
{
// 对前后两个数字进行比较,将数字较小的前移
if (IntegerArray[j] <= IntegerArray[j - 1])
{
InterVariables = IntegerArray[j];
IntegerArray[j] = IntegerArray[j - 1];
IntegerArray[j - 1] = InterVariables;
}
}
}
}
int main()
{
// 初始化数组
int IntegerArray[15] = { 5, 8, 9, 0, 2, 1, 4, 7, 6, 3, 21};
// 得到数组长度
int length = sizeof(IntegerArray) / sizeof(IntegerArray[0]);
// 数组升序排列
MySort(IntegerArray, length);
// 循环输出排序后的数组
for (int i = 0; i < length; i++)
{
cout << IntegerArray[i] << " ";
}
cout << endl;
return 0;
}