排序算法
来源:互联网 发布:蒋欣 长相 知乎 编辑:程序博客网 时间:2024/05/21 09:43
//Quick_Sort
int Partion(int *str, int i, int j) {
int flag = str[i];
while(i < j) {
while(i < j && str[j] >= flag) {
j--;
}
if(i < j) {
str[i++] = str[j];
}
while(i < j && str[i] <= flag) {
i++;
}
if(i < j) {
str[j--] = str[i];
}
}
str[i] = flag;
return i;
}
void Quick_Sort(int *str, int low, int high) {
int pos;
if(low < high) {
pos = Partion(str, low, high);
Quick_Sort(str, low, pos - 1);
Quick_Sort(str, pos + 1, high);
}
}
//Bubble_Sort
int Bubble_Sort(int *pArray, int n) {
for(int i = 0; i < n - 1; i++) {
for(int j = i + 1; j < n; j++) {
if(pArray[i] > pArray[j]] {
swap(pArray[i], pArray[j]);
}
}
}
}
//Insert_Sort
void Insert_Sort(int array[], int length) {
int key;
for(int i = 1; i < length; i++) {
key = array[i];
for(int j = i - 1; j >= 0 && array[j] > key; j--) {
array[j + 1] = array[j];
}
array[j + 1] = key;
}
}
//Shell_Sort
void Shell_Sort(int array[], int length) {
for(int increment = length / 2; increment > 0; increment /= 2) {
int key;
for(int i = increment; i < length; i++) {
key = array[i];
for(int j = i - increment; j >= 0 && a[j] > key; j -= increment) {
array[j + increment] = array[j];
}
array[j + increment] = key;
}
}
}
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- error while loading shared libraries的解決方法
- 每日程炼-IOUtils 单元(4): TDirectory.GetDirectories获取子目录
- main函数返回值return 0
- 你的成功在于你每天养成的习惯
- 每日程炼-IOUtils 单元(5): TDirectory 的其他功能
- 排序算法
- IOUtils 单元(6): TPath(结构体)路径的提取和处理
- 关于Flash Builder 4.x的概要分析
- IOUtils 单元(7): TFile 文件操作
- 使用CPU时间戳进行高精度计时
- poj1189
- poj3625
- 魔方阵
- 用协议分析工具学习TCP/IP