//******************快速排序非递归算法(队列实现)*****************************

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;          }      } }

    原文作者:递归算法
    原文地址: https://blog.csdn.net/u014230945/article/details/69770619
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞