⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4.cpp

📁 好啊
💻 CPP
字号:
#include "stdio.h"
#include "iostream.h"
#define MAXSIZE 100
typedef struct{
 	int key;
 	int other;
}RecordType;
typedef struct{
	RecordType r[MAXSIZE+1];
	int length;
}SqeList;

int Partition(SqeList *H,int left,int right){
    static int n=1,i;
 	RecordType x;int low,high;x=H->r[left];low=left;high=right;
 	while(low<high){
while(H->r[high].key>=x.key&& low< high ) high--;
 		if(low<high ){H->r[low]=H->r[high];low++;}
while(H->r[low].key<x.key &&low<high) low++;
 		if(low<high){H->r[high]= H->r[low];high--;}
}
H->r[low]=x;

printf("第");cout<<n;printf("趟排序为:");
for(i=0;i<H->length;i++) printf("%4d",H->r[i].key);
printf("\n"); n++;
return low;
}
void QuickSort(SqeList *L,int low,int high){
int mid;
if(low<high){mid=Partition(L,low,high);
	         QuickSort(L,low,mid-1);
			 QuickSort(L,mid+1,high);			 
}}
void main(){
SqeList L,*p=&L;int i;
cout<<"请输入要排序的数据个数:";
scanf("%d",&L.length);
cout<<"请输入数据:"<<endl;
for(i=0;i<L.length;i++)scanf("%d",&L.r[i].key);
printf("原数据为:");
for(i=0;i<L.length;i++)printf("%4d",L.r[i].key);printf("\n");
QuickSort(p,0,8);
printf("\n排序后为:");
for(i=0;i<L.length;i++)printf("%4d",L.r[i].key);
printf("\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -