快速排序版本二
2012-12-06 14:59
155 查看
1 #include
<iostream>
2 #include
<stdio.h>
3 #include
<stdlib.h>
4 using namespace std;
5
6 int Partition(int *a, int m, int
n);
7
8 void QuickSort(int *a, int low, int
high)
9 {
10
int pivot;
11
if(low <
high)
12
{
13
pivot =
Partition(a, low, high);
14
QuickSort(a, low, pivot - 1);
15
QuickSort(a, pivot + 1, high);
16
}
17 }
18
19 int Partition(int *a, int m, int n)
20 {
21
int t;
22
int temp = a[m];
23
int i = m;
24
int j = n + 1;
25
while(i <
j)
26
{
27
while(i
< j && a[--j]
>= temp);
28
while(i
< j && a[++i]
<= temp);
29
if(i
< j)
30
{
31
t = a[i];
32
a[i] = a[j];
33
a[j] = t;
34
}
35
}
36
t = a[m];
37
a[m] = a[j];
38
a[j] = t;
39
return j;
40 }
41
42 int main()
43 {
44
int
i;
45
int *a = (int
*)malloc(sizeof(int) * 10);
46
cout<<"intput 10
nuber:"<<endl;
47
for(i = 0; i <
10; i++)
48
{
49
cin>>a[i];
50
}
51
QuickSort(a, 0, 9);
52
cout<<"After quick
sort:"<<endl;
"test07.cpp" 59L, 862C 已写入
15,13-27
顶端
<iostream>
2 #include
<stdio.h>
3 #include
<stdlib.h>
4 using namespace std;
5
6 int Partition(int *a, int m, int
n);
7
8 void QuickSort(int *a, int low, int
high)
9 {
10
int pivot;
11
if(low <
high)
12
{
13
pivot =
Partition(a, low, high);
14
QuickSort(a, low, pivot - 1);
15
QuickSort(a, pivot + 1, high);
16
}
17 }
18
19 int Partition(int *a, int m, int n)
20 {
21
int t;
22
int temp = a[m];
23
int i = m;
24
int j = n + 1;
25
while(i <
j)
26
{
27
while(i
< j && a[--j]
>= temp);
28
while(i
< j && a[++i]
<= temp);
29
if(i
< j)
30
{
31
t = a[i];
32
a[i] = a[j];
33
a[j] = t;
34
}
35
}
36
t = a[m];
37
a[m] = a[j];
38
a[j] = t;
39
return j;
40 }
41
42 int main()
43 {
44
int
i;
45
int *a = (int
*)malloc(sizeof(int) * 10);
46
cout<<"intput 10
nuber:"<<endl;
47
for(i = 0; i <
10; i++)
48
{
49
cin>>a[i];
50
}
51
QuickSort(a, 0, 9);
52
cout<<"After quick
sort:"<<endl;
"test07.cpp" 59L, 862C 已写入
15,13-27
顶端
相关文章推荐
- CLRS 7.3快速排序的随机化版本
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- 每日编程3之快速排序随机化版本
- 快速排序(递归版本)
- 快速排序 --Java版本
- 各种常见的排序 java版本(冒泡,选择,插入,希尔,快速)
- 快速排序各种版本(record)
- RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->Web版本模块管理界面新增模块排序功能
- 快速排序随机化版本
- 算法导论7.3快速排序的随机化版本
- 算法导论 第2版 7.3 快速排序随机化版本
- 《算法导论》笔记 第7章 7.3快速排序的随机化版本
- 快速排序的java版本
- 快速排序随机化版本
- 第七章快速排序之“快速排序Hoare版本HOARE-QUICKSORT”(思考题7-1)
- 快速排序的随机化版本
- 快速排序的随机化版本代码
- 快速排序之随机化版本(7)
- 《算法导论》笔记 第7章 7.3快速排序的随机化版本
- 快速排序(C语言版本)