//#include <bits/stdc++.h>
#include <iostream>
using namespace std;
/*
冒号排序:
冒泡排序(BubbleSort)的基本方法是:设待排序元素序列的元素个数为n,从后向前两两比较相
邻元素的值,如果发生逆序(即前一个比后一个大),则交换它们,直到序列比较完。我们称它为一
趟冒泡,结果是最小的元素交换到待排序序列的第一个位置,其他元素也都向排序的最终位置移动。
下一趟冒泡时前一趟确定的最小元素不参加比较,待排序序列减少一个元素,一趟冒泡的结果又把
序列中最小的元素交换到徒排序序列的第一个位置。这样最多做n-1趟冒泡就能把所有元素排好序。
*/
int arr[] = { 8,5,3,1,6,7,2,9,10,4 };
typedef int temp;
void bubble_sort()
{
int start = 0;
int end = 10;
int i, j ,exchange= 0;
temp tmp = 0;
for (i=start;i< end -1;i++)
{
exchange = 0;
for (j=end-1;j>start;j--)//发生逆序,交换位置
{
if (arr[j-1]>arr[j])
{
tmp = arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = tmp;
exchange = 1;
}
}
if (exchange == 0)//本趟无逆序,结束
return;
}
}
int main()
{
bubble_sort();
for (int i=0;i<10;i++)
{
cout << arr[i]<<" ";
}
cout << endl;
return 0;
}