冒泡排序
void BubbleSort(int *buff, int len)
{
int flag;
for (int i = 0; i < len - 1; i++) {
flag = 0;
for (int j = 0; j < len - 1 - i; j++) {
if(buff[j + 1] >= buff[j]){
continue;
}
flag = 1;
buff[j] ^= buff[j + 1];
buff[j + 1] ^= buff[j];
buff[j] ^= buff[j + 1];
}
if (flag == 0) {
break;
}
}
}
选择排序
void SelectSort(int *buff, int len)
{
int index;
for (int i = 0; i < len - 1; i++) {
index = i;
for (int j = i + 1; j < len; j++) {
if(buff[index] > buff[j]){
index = j;
}
}
if (index != i) {
buff[index] = buff[index] + buff[i];
buff[i] = buff[index] - buff[i];
buff[index] = buff[index] - buff[i];
}
}
}
插入排序