快速排序
来源:互联网 发布:大学生网络诈骗感悟 编辑:程序博客网 时间:2024/05/18 01:07
//============================================================================
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <assert.h>
#include <string.h>
using namespace std;
int partion(int a[], int start, int end) {
int temp = a[start];
while (start < end) {
while (a[end] > temp && start < end)
end--;
a[start] = a[end];
while (a[start] < temp & start < end)
start++;
a[end] = a[start];
}
a[start] = temp;
return start;
}
void quick_sort(int a[],int start,int end)
{
if(start<end)
{
int k=partion(a,start,end);
quick_sort(a,start,k-1);
quick_sort(a,k+1,end);
}
}
int main() {
int a[10]={1,3,2,4,6,5,7,10,9,8};
quick_sort(a,0,9);
for (int i = 0; i < 10; ++i) {
cout<<a[i];
}
return 0;
}
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <assert.h>
#include <string.h>
using namespace std;
int partion(int a[], int start, int end) {
int temp = a[start];
while (start < end) {
while (a[end] > temp && start < end)
end--;
a[start] = a[end];
while (a[start] < temp & start < end)
start++;
a[end] = a[start];
}
a[start] = temp;
return start;
}
void quick_sort(int a[],int start,int end)
{
if(start<end)
{
int k=partion(a,start,end);
quick_sort(a,start,k-1);
quick_sort(a,k+1,end);
}
}
int main() {
int a[10]={1,3,2,4,6,5,7,10,9,8};
quick_sort(a,0,9);
for (int i = 0; i < 10; ++i) {
cout<<a[i];
}
return 0;
}
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 自己写一个DropDownList控件
- 嘻唰唰第四批之学生信息的输入输出
- 008.Enum 枚举型
- CoreAnimation编程指南(简介)
- 1010. Radix (25)
- 快速排序
- UITextView学习记录
- 黑马程序员--Foundation
- intellij IDEA序列号
- Tomcat搭建文件服务器
- poj1273
- MySQL版本查询以及生成的数据表文件路径
- SQL-T-SQL语句
- 009.BOOL 布尔类型