QuickSort
来源:互联网 发布:·手机淘宝 编辑:程序博客网 时间:2024/06/05 00:18
#include<stdio.h>
#define MAXE 20
typedef int KeyType;
typedef char InfoType;
typedef struct
{
KeyType key;
InfoType data;
}RecType;
void QuickSort(RecType R[],int s,int t)
{
int low=s,high=t;
R[0]=R[low];
RecType pivotkey=R[s];
while(low!=high){
while(low<high&&R[high].key>pivotkey.key)
--high;
if(low<high)
R[low++]=R[high];
while(low<high&&R[low].key<pivotkey.key)
++low;
if(low<high)
R[high--]=R[low];
}
R[low]=pivotkey;
printf("划分区间为R[%d..%d],结果为:",low,high);
for(int k=0;k<10;k++)
if(k==low)
printf("[%d]",R[k].key);
else
printf("%3d",R[k].key);
printf("\n");
QuickSort(R,s,low-1);
QuickSort(R,low+1,t);
}
#define MAXE 20
typedef int KeyType;
typedef char InfoType;
typedef struct
{
KeyType key;
InfoType data;
}RecType;
void QuickSort(RecType R[],int s,int t)
{
int low=s,high=t;
R[0]=R[low];
RecType pivotkey=R[s];
while(low!=high){
while(low<high&&R[high].key>pivotkey.key)
--high;
if(low<high)
R[low++]=R[high];
while(low<high&&R[low].key<pivotkey.key)
++low;
if(low<high)
R[high--]=R[low];
}
R[low]=pivotkey;
printf("划分区间为R[%d..%d],结果为:",low,high);
for(int k=0;k<10;k++)
if(k==low)
printf("[%d]",R[k].key);
else
printf("%3d",R[k].key);
printf("\n");
QuickSort(R,s,low-1);
QuickSort(R,low+1,t);
}
0 0
- Quicksort
- QuickSort
- quicksort
- quicksort
- QuickSort
- QuickSort
- QuickSort
- QuickSort
- QuickSort
- QuickSort
- quicksort
- QuickSort
- QuickSort
- QuickSort
- quicksort
- quicksort
- QuickSort
- Quicksort
- drupal7 常用API
- MergeSort
- lua--简明教程
- 使用keytool对证书进行操作
- 数据库——关系代数除法
- QuickSort
- lua资源
- 线段树入门二题
- 动态创建对话框方法
- SQL高级查询技巧
- Activity与Fragment切换动画
- 【LeetCode从零单刷】Intersection of Two Linked Lists
- Ajax成功添加新DOM元素 jquery 绑定元素事件
- C#基础知识回归