#include <>
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int Status;
typedef int KeyType;
typedef struct
{
KeyType key;
}ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList_Sq(SqList &L)
{
=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (!) exit(OVERFLOW);
=0;
=LIST_INIT_SIZE;
return OK;
}
Status ListInsert_Sq(SqList &L,int i,ElemType e)
{
ElemType *newbase,*p,*q;
if (i<1||i>+1) return ERROR;
if (>=)
{
newbase=(ElemType*)realloc(,(+LISTINCREMENT)*sizeof(ElemType));
if (!newbase) exit (OVERFLOW);
=newbase;
+=LISTINCREMENT;
}
q=&([i-1]);
for (p=&([-1]);p>=q;p--) *(p+1)=*p;
*q=e;
++;
return OK;
}
void Disp_Sq(SqList &L)
{
int i;
for (i=1;i<;i++)
{
printf("%d",([i]).key);
if(i<-1)
printf(".");
}
printf("\n");
}
Status Partition(SqList &L,int low,int high)
{
int pivotkey;
[0]=[low];
pivotkey=[low].key;
while(low<high)
{
while(low<high&&[high].key>=pivotkey) --high;
[low]=[high];
while(low<high&&[low].key<=pivotkey) ++low;
[high]=[low
快速排序 来自淘豆网m.daumloan.com转载请标明出处.