下载此文档

快速排序.doc


文档分类:IT计算机 | 页数:约4页 举报非法文档有奖
1/4
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/4 下载此文档
文档列表 文档介绍
#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转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数4
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xunlai783
  • 文件大小22 KB
  • 时间2018-11-26
最近更新