下载此文档

快速排序非递归算法.doc


文档分类:IT计算机 | 页数:约2页 举报非法文档有奖
1/2
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/2 下载此文档
文档列表 文档介绍
//******************快速排序非递归算法(队列实现)*****************************
const int Maxsize = 100;
void quicksortu(int a[],int n)
{
struct node
{
int low,high;
}qu[Maxsize];
int i,j,low,high,temp,front=-1,rear=-1;
rear++;
qu[rear].low=0;
qu[rear].high=n-1;
while(front!=rear)
{
front=(front+1)%Maxsize;
low=qu[front].low;
high=qu[front].high;
i=low;
j=high;
if(low<high)
{ temp=a[low];
while(i!=j)
{ while(i<j&&a[j]>temp)j--;
if(i<j){a[i]=a[j];i++;}
while(i<j&&a[i]<temp)i++;
if(i<j){a[j]=a[i];j--;}
}
a[i]=temp;
rear=(rear+1)%Maxsize;
qu[rear].low=low;
qu[rear].high=i-1;
rear=(rear+1)%Maxsize;
qu[rear].low=i+1;
qu[rear].high=high;
}
}
}
struct node
{
int low,high;
}st[100];
//******************快速排序非递归算法(堆栈实现)*****************************
void quicksort(int a[],int n)
{ int i,j,low,high,temp,top=0;

st[top].low=0;
st[

快速排序非递归算法 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数2
  • 收藏数0 收藏
  • 顶次数0
  • 上传人mh900965
  • 文件大小30 KB
  • 时间2018-05-12