1、实验:第十章 排序软件二班 杨文庄 E01014330/希尔排序和快速排序/ 排序.cpp : Defines the entry point for the console application./#include “stdafx.h“#include“stdio.h“#include“string.h“#include“stdlib.h“#define OK 1#define N 10#define MAXSIZE 100#define OVERFLOW -1typedef int KeyType;typedef structint rMAXSIZE+1;/r0闲置或用作哨兵单元int
2、length;/顺序表长度SqList;/顺序表类型void swap(SqList L.ri=L.rj; L.rj=temp; void print(SqList L)for(int i=1;iri插入有序增量子表 */ L.r0=L.ri; /* 暂存在 L-r0 */for(j=i-increment;j0 int Partition(SqList pivotkey=L.rlow; /* 用子表的第一个记录作枢轴记录 */while(low=pivotkey)high-;swap(L,low,high);/* 将比枢轴记录小的记录交换到低端 */while(lowrlowhigh一分为二
3、,算出枢轴值 pivot */QSort(L,low,pivot-1); /* 对低子表递归排序 */QSort(L,pivot+1,high); /* 对高子表递归排序 */void QuickSort(SqList int main()int i;int dN=49,38,65,97,76,13,27,49,55,04;SqList La,Lb;for(i=0;iN;i+)La.ri+1=di;La.length=N;Lb=La;printf(“排序前顺序表为: “);print(La);printf(“希尔排序为: n“);ShellSort(La);print(La);printf(“快速排序为: “);QuickSort(Lb);print(Lb);return OK;