#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
void BubbleSort(vector<int> &a, int low, int high)
{
int c = 0;
int count = 0;//记录有无发送交换 ,当其=0时,不必再排序
for (int i = low; i < high; i++)
{
for (int j = high - 1; j >= 0; j--)
{
if (a[j] > a[j+1])
{
swap(a[j], a[j+1]);
count++;
}
}
if (count == 0) break;
}
}
int main()
{
vector <int> a = { 10, 1, 2, 6, 3,'a', 1,6,1};
BubbleSort(a, 0, a.size() - 1);
for (int i = 0; i < a.size(); i++)
std::cout << a[i] << ' ';
system("pause");
return 0;
}
运行结果: