?? xuanze2.txt
字號:
//選擇排序法(下沉)xuanze2.cpp
#include<iostream.h>
#include<iomanip.h>
#define N 10
void gensort(int b[],int n)
{int i,j,k;
for(i=1;i<n;i++)
{k=n-i;
for(j=n-i-1;j>=0;j--)
if(b[k]<b[j]) k=j;
if(k!=n-i)
{int temp=b[k];b[k]=b[n-i];b[n-i]=temp;}
for(int m=0;m<N;m++)
cout<<setw(4)<<b[m];cout<<endl;}
}
//選擇排序法測試
void main()
{cout<<"xuanze2.cpp運行結果:\n";
int ai[N],i,m;
for(i=0;i<N;i++) ai[i]=random(101+i)%100;
cout<<"排序前數組:\n";
for(i=0;i<N;i++)
cout<<setw(4)<<ai[i];
cout<<endl<<"排序過程演示:\n";
gensort(ai,sizeof(ai)/sizeof(int));
cout<<"排序后數組:\n";
for(i=0;i<N;i++)
cout<<setw(4)<<ai[i];
cout<<endl;cin.get();}
xuanze2.cpp運行結果:
排序前數組:
26 72 2 88 87 11 15 90 59 61
排序過程演示:
26 72 2 88 87 11 15 61 59 90
26 72 2 59 87 11 15 61 88 90
26 72 2 59 61 11 15 87 88 90
26 15 2 59 61 11 72 87 88 90
26 15 2 59 11 61 72 87 88 90
26 15 2 11 59 61 72 87 88 90
11 15 2 26 59 61 72 87 88 90
11 2 15 26 59 61 72 87 88 90
2 11 15 26 59 61 72 87 88 90
排序后數組:
2 11 15 26 59 61 72 87 88 90
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -