快速排序 C代码
来源:互联网 发布:身份证被别人淘宝开店 编辑:程序博客网 时间:2024/04/29 21:56
#include<iostream.h>
#define MIXSIZE 20
typedef struct
{
int key;
int otherinfo;
}Redtype;
typedef struct
{
Redtype r[MIXSIZE+1];
int length;
}Sqlist;
int Partition(Sqlist &L,int low,int high)
{
int pivotkey;
L.r[0]=L.r[low];
pivotkey=L.r[low].key;
while(low<high)
{
while(low<high&&L.r[high].key>=pivotkey) --high;
L.r[low]=L.r[high];
while(low<high&&L.r[low].key<=pivotkey) ++low;
L.r[high]=L.r[low];
}
L.r[low]=L.r[0];
return low;
}
void QSort(Sqlist &L,int low,int high)
{
if(low<high)
{
int pivotloc;
pivotloc=Partition(L,low,high);
QSort(L,low,pivotloc-1);
QSort(L,pivotloc+1,high);
}
}
void Quicksort(Sqlist &L)
{
QSort(L,1,L.length);
}
void Output(Sqlist L)
{
int i;
for(i=1;i<=L.length;i++)
cout<<L.r[i].key<<" ";
cout<<endl;
}
void main()
{
Sqlist s;
int t;
cout<<"请输入线形表的长度:";
cin>>s.length;
for(int i=1;i<=s.length;i++)
{cin>>t;
s.r[i].key=t;}
Quicksort(s);
Output(s);
}
- 快速排序 C代码
- c代码--快速排序问题
- c代码--快速排序问题
- 快速排序C语言代码
- c语言快速排序代码
- Objective-C 快速排序代码
- 【排序】 快速排序代码-C语言版
- 快速排序的C语言代码实现
- 快速排序的C语言代码实现
- 快速排序的C语言代码实现
- 快速排序 qsort c语言代码
- 快速排序的C语言代码实现
- 快速排序算法C,JAVA代码
- C语言快速排序算法代码分析
- 编程算法 - 快速排序算法 代码(C)
- C语言快速排序算法及代码
- 优化快速排序 C语言代码
- 快速排序的c语言实现代码
- UML笔记
- 让你写前台JS,但是你不喜欢,你会怎么选择。
- display:inline 怎么用
- 惹眼
- pl/SQL中的汉化包
- 快速排序 C代码
- 感觉
- 递归与迭代
- c中const
- 发现ThinkPHP的bug官网上却不知找谁
- JS 经典效果集锦 (一)
- JavaScript经典效果集锦之二
- JavaScript经典效果集锦之三
- JavaScript经典效果集锦之四,五