📄 排序 -- 选择排序法.txt
字号:
/******************************************************************************************************
** Program Name : Selection Sort
** Author : Lu Jian Hua
** Time : 2007-9-5
*******************************************************************************************************/
#include <iostream>
using namespace std ;
const int MAX_SIZE = 20;
void Select_Sort(int *a, const int SIZE) ;
int main()
{
int a[MAX_SIZE] = { 0 } ;
cout << "-------------- Selection Sort ----------------------" << endl << endl
<< "Please Enter The Numbers : " << endl << endl ;
for (int i=0; i<MAX_SIZE; i++)
{
cout << "a[" << i << "] : " ;
cin >> a[i] ;
}
cout << "Before Sorting : " ;
for (i=0; i<MAX_SIZE; i++)
cout << a[i] << " " ;
Select_Sort(a, MAX_SIZE) ;
cout << endl << endl ;
cout << "After Sorting : " ;
for (i=0; i<MAX_SIZE; i++)
cout << a[i] << " " ;
cout << endl << endl ;
cout << "-------------- Selection Sort ----------------------" << endl << endl ;
return 0 ;
}
void Select_Sort(int *a, const int SIZE)
{
int temp = 0 ;
for (int i=0; i <= SIZE-2; i++) // Outer Loop : 0 ~ SIZE-2
{
for (int j = i+1; j <= SIZE-1; j++) // Inner Loop : i+1 ~ SIZE-1
{
if (a[i] > a[j])
{
temp = a[i] ;
a[i] = a[j] ;
a[j] = temp ;
}
}
}
}
/********************************************************************************
*
* Notice : This Program Can Be Launched In VC6.0 Environment
*
********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -