1、冒泡排序
基本思想:两个数比较大小,小的数放在大的数前面(升序)
实现流程:
1、比较相邻的两个数组元素A和B,如果A > B,就交换A 、B的位置,否则不做改变。
2、从后往前对数组元素进行两两比较,一直到最前两个的两个元素。最终数组中最小值被交换到起始的位置。
#include <stdio.h>
#define SIZE (10)
void Swap(int *a, int *b)
{
/*使用位运算: 按位与进行数据交换*/
(*a) = (*a)^(*b);
(*b) = (*a)^(*b);
(*a) = (*a)^(*b);
}
void BubbleSort(int *arr, int len)
{
/* 外层循环决定循环几轮*/
for (int i = len-1;i > 1;