?? 4.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<<"請輸入要排序的數(shù)據(jù)個數(shù):";
scanf("%d",&L.length);
cout<<"請輸入數(shù)據(jù):"<<endl;
for(i=0;i<L.length;i++)scanf("%d",&L.r[i].key);
printf("原數(shù)據(jù)為:");
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 + -