C++冒泡排序
//冒泡排序
void bubbleOrder(vector<int>& data)
{
int length = data.size();
int flag = 0;
int temp;
for (int i = 0; i < length; i++)
{
flag = 0;
for (int j = length - 1; j > i + 1; j--)
{
if (data[j - 1] > data[j])
{
flag = 1;
temp = data[j];
data[j] = data[j - 1];
data[j - 1] = temp;
}
}
if (!flag)
break;
}
}
void bubbleOrder(vector<int>& data)
{
int length = data.size();
int flag = 0;
int temp;
for (int i = 0; i < length; i++)
{
flag = 0;
for (int j = length - 1; j > i + 1; j--)
{
if (data[j - 1] > data[j])
{
flag = 1;
temp = data[j];
data[j] = data[j - 1];
data[j - 1] = temp;
}
}
if (!flag)
break;
}
}