#include <iostream>
using namespace std;
typedef int Keytype;
Keytype NUM[10]={2,98,123,54,67,88,4,900,56,76};
struct LinearList
{
Keytype *key;
int length;
int maxsize;
};
void CreatLinearList(LinearList &L,int Maxsize)
{
L.maxsize=Maxsize;
L.length=0;
L.key=new Keytype[L.maxsize];
};
int Partition(Keytype r[],int low,int high)
{
Keytype temp;
int StandardKey;
StandardKey=r[low];
temp=r[low];
if(low<high)
{
while(low<high&&StandardKey<=r[high])
high--;
r[low++]=r[high];
while(low<high&&StandardKey>=r[high])
low++;
r[high--]=r[low];
}
r[high]=temp;
return high;
}
void QSort(Keytype r[],int low,int high)
{
int StandardLoc;
while(low<high-1)
{
StandardLoc=Partition(r,low,high);
QSort(r,low,StandardLoc-1);
QSort(r,StandardLoc+1,high);
}
}
void QuickSort(LinearList &L)
{
QSort(L.key,0,L.length-1);
}
void Output(LinearList &L)
{
for(int i=0;L.length!=0;L.length--,i++)
{
cout<<L.key[i]<<" ";
}
}
int main()
{
LinearList L;
CreatLinearList(L,20);
int i;
for(i=0;i<10;i++)
{
L.key[i]=NUM[i];
L.length++;
}
Output(L);
QuickSort(L);
cout<<endl;
Output(L);
}
有几个地方写错了,参考下面代码,在你的代码的基础上修改的,有说明:
#include <iostream>