?? selectsort.cpp
字號:
#include <stdio.h>
#include <iostream.h>
#define MAX 255
int R[MAX];
void Select_Sort(int n)
{
int i,j,k;
for(i=1;i<n;i++)
{
k=i;
for(j=i+1;j<=n;j++) /* 在當前無序區R[i..n]中選key最小的記錄R[k] */
if(R[j]<R[k])
k=j; /* k記下目前找到的最小關鍵字所在的位置 */
if(k!=i)
{ /* 交換R[i]和R[k] */
R[0]=R[i]; R[i]=R[k]; R[k]=R[0]; /* R[0]作暫存單元 */
} /* endif */
} /* endfor */
} /* end of Select_Sort */
void main()
{
int i,n;
cout << "Please input total element number of the sequence:" ;
cin >> n;
if(n<=0||n>MAX)
{
cout << "n must more than 0 and less than" << MAX;
}
cout << "Please input the elements one by one:" << endl;
for(i=1;i<=n;i++)
cin >> R[i];
cout << "The sequence you input is:" ;
for(i=1;i<=n;i++)
cout << " " << R[i] ;
Select_Sort(n);//選擇排序
cout << endl << endl;
cout << "The sequence after select_sort is:" ;
for(i=1;i<=n;i++)
cout << " " << R[i];
cout << endl << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -