?? quicksort.cpp
字號:
#include<iostream>
#include<string>
using namespace std;
#define MAXSIZE 20
typedef struct
{
int key;
}Rtype;
typedef struct
{
Rtype r[MAXSIZE+1];
int length;
}Sqlist;
int Parttition(Sqlist &L,int low,int high)
{
L.r[0]=L.r[low];
int pivotkey=L.r[low].key;
while(low<high)
{
while(low<high && L.r[high].key>=pivotkey)
--high;
L.r[low]=L.r[high];
while(low<high && L.r[high].key<=pivotkey)
++low;
L.r[high]=L.r[low];
}
L.r[low]=L.r[0];
return low;
}
void Qsort(Sqlist &L,int low,int high)
{
if(low<high)
{
int pivotloc=Parttition(L,low,high);
Qsort(L,low,pivotloc);
Qsort(L,pivotloc+1,high);
}
}
void QuickSort(Sqlist &L)
{
Qsort(L,1,L.length);
}
int main()
{
Sqlist L;
cout<<"請輸入數(shù)列的數(shù)字的個數(shù)"<<endl;
int k;
cin>>k;
cout<<"請輸入一個無序的序列"<<endl;
for(int i=1;i<=k;i++)
{
cin>>L.r[i].key;
}
L.length=k;
QuickSort(L);
cout<<"排列好的順序(從小到大的順序)是"<<endl;
for(int i=1;i<=k;i++)
cout<<L.r[i].key<<" ";
cout<<endl;
system("pause");
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -