冒泡排序,为稳定排序,时间复杂度为O(n2)
void BubbleSort(int buf[], int n)
{
int i = 0;
int j = 0;
int tmp = 0;
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - i -1; j++)
{
if (buf[j] > buf[j+1])
{
tmp = buf[j];
buf[j] = buf[j+1];
buf[j+1] = tmp;
}
}
}
}