#include<iostream>
using namespace std;
void quick(int A[],int N,int Beg,int End,int *locptr)
{
int left,right,temp;
left=Beg;
right=End;
*locptr=Beg;
step2:
while((A[*locptr]<A[right])&& ((*locptr)!=right))
{
right--;
}
if(*locptr==right)
{
return;
}
if(A[*locptr]>A[right])
{
temp=A[*locptr];
A[*locptr]=A[right];
A[right]=temp;
*locptr=right;
}
goto step3;
step3:
while((A[left]<A[*locptr])&& ((*locptr)!=left))
{
left++;
}
if(*locptr==left)
{
return;
}
if(A[left]>A[*locptr])
{
temp=A[*locptr];
A[*locptr]=A[left];
A[left]=temp;
*locptr=left;
}
goto step2;
}
void quick_sort(int A[],int N)
{
int beg,end,loc,top=-1;
int lower[10],upper[10];
if(N>1)
{
top++;
lower[top]=0;
upper[top]=N-1;
}
while(top!=-1)
{
beg=lower[top];
end=upper[top];
top--;
quick(A,N,beg,end,&loc);
if(beg<loc-1)
{
top++;
lower[top]=beg;
upper[top]=loc-1;
}
if(loc+1<end)
{
top++;
lower[top]=loc+1;
upper[top]=end;
}
}
}
int main()
{
int A[]={44,33,11,55,77,90,40,60,99,22,88,66};
quick_sort(A,12);
for(int i=0; i<12; i++)
{
cout<<A[i]<<"t";
}
return 0;
}
0 Comments