?? h4.cpp
字號:
#include<iostream>#include<cstdio>using namespace std;int Partition(int* a,int p,int r);void QuickSort(int* a,int p,int r);int Partition(int* a,int p,int r) //實現分治{ int x=a[r],i=p-1; for(int j=p;j<=r-1;j++) if(a[j]<=x) { int temp=a[j]; a[j]=a[i+1]; a[i+1]=temp; i++; } int t=a[r]; a[r]=a[i+1]; a[i+1]=t; return i+1;}void QuickSort(int* a,int p,int r) //快速排序{ int q; if(p<r) { q=Partition(a,p,r); QuickSort(a,p,q-1); QuickSort(a,q+1,r); } else return;}int main(void){ int a[8]; cout<<"Please input 8 number:\n"; for(int i=0;i<8;i++) scanf("%d",&a[i]); QuickSort(a,0,7); for(int j=0;j<8;j++) printf("%3d",a[j]); cout<<"\n"; return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -