标签:iostream 变量 第一个 pad main 数组 code log namespace
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include<iostream>#include<cstdio>#include<cstdlib>#include<ctime>#define SIZE 15using namespace std;void selectSort(int *a, int len){ int h; int tmp; for(int i=0; i<SIZE-1; i++){ int k=i; for(int j=i+1; j<len; j++){ if(a[j]<a[k]) k=j; } if(k!=i){ tmp=a[i]; a[i]=a[k]; a[k]=tmp; } cout<<"第"<<i<<"步排序结果为:"; for(int h=0; h<len ; h++){ cout<<a[h]<<" "; } cout<<endl; }}int main(){ int array[SIZE]; srand(time(NULL)); for(int i=0 ;i<SIZE; i++){ array[i]=rand()/1000+100; } cout<<"排序前的序列为:"<<endl; for(int i=0; i<SIZE; i++){ cout<<array[i]<<" "; } cout<<endl<<endl; selectSort(array, SIZE); cout<<endl; cout<<"排序后的序列为:"<<endl; for(int i=0; i<SIZE; i++){ cout<<array[i]<<" "; } return 0;} |
运行结果:

标签:iostream 变量 第一个 pad main 数组 code log namespace
原文地址:http://www.cnblogs.com/wangchaoyuana/p/7497320.html