快排
来源:互联网 发布:湖北大学知行学院 编辑:程序博客网 时间:2024/04/27 17:26
#include <stdio.h>
int a[10] = {3, 4, 2, 9, 8, 1, 7, 0, 5};
int partition(int *a, int low, int high)
{
int temp = a[low];
while(low < high)
{
while((low < high) && (a[high] >= temp))
{
--high;
}
a[low] = a[high];
while((low < high) && (a[low] <= temp))
{
++low;
}
a[high] = a[low];
}
a[low] = temp;
return low;
}
void print(int *a)
{
for(int i = 0; i < 9; ++i)
{
printf("%d ", *a++);
}
printf("\n");
}
void QSort(int *a, int low, int high)
{
if(low < high)
{
int pivot = partition(a, low, high);
print(a);
QSort(a, low, pivot - 1);
QSort(a, pivot + 1, high);
}
}
int main()
{
a[9] = '\0';
QSort(a, 0, 8);
print(a);
return 0;
}
int a[10] = {3, 4, 2, 9, 8, 1, 7, 0, 5};
int partition(int *a, int low, int high)
{
int temp = a[low];
while(low < high)
{
while((low < high) && (a[high] >= temp))
{
--high;
}
a[low] = a[high];
while((low < high) && (a[low] <= temp))
{
++low;
}
a[high] = a[low];
}
a[low] = temp;
return low;
}
void print(int *a)
{
for(int i = 0; i < 9; ++i)
{
printf("%d ", *a++);
}
printf("\n");
}
void QSort(int *a, int low, int high)
{
if(low < high)
{
int pivot = partition(a, low, high);
print(a);
QSort(a, low, pivot - 1);
QSort(a, pivot + 1, high);
}
}
int main()
{
a[9] = '\0';
QSort(a, 0, 8);
print(a);
return 0;
}
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排。
- 提高 web 应用性能之 JavaScript 性能调优
- DeviceIoControl错误码:87
- box2d学习小资料自己总结
- 部署项目到weblogic中出现 The error is weblogic.descriptor.DescriptorException: Unmarshaller failed
- 如何在Linux下创建与解压zip, tar, tar.gz和tar.bz2文件
- 快排
- 代码控制控件可用性和可见性
- 闭包举例
- 《python核心编程》整理(1)
- t检验与F检验 /统计常识 / 统计学笔记(转载)
- Deep discussion on method of judging a system whether a little endian or big endian
- 简单的网站项目开发流程 .
- Tomcat服务器配置参考-路径指向
- 字符设备驱动之Hello World