标签:blog http os io ar for 2014 sp log
#include<iostream> using namespace std; int getMinValue(int* input, int i, int len){ int minIndex = i; for(int j=i;j<len;j++){ if(input[minIndex]>input[j]) minIndex = j; } return minIndex; } void exchange(int* input, int frist, int second){ input[frist] = input[frist] + input[second]; input[second] = input[frist] - input[second]; input[frist] = input[frist] - input[second]; } void selectSort(int* input, int len){ for(int i=0;i<len-1;i++){ int minIndex = getMinValue(input,i,len); if(minIndex!=i) exchange(input,i,minIndex); } } void output(int* input, int len){ for(int i=0;i<len;i++) cout<<input[i]<<" "; } void main(){ int input[] = {12,4,2,1,6,3,11,6,0,-5,1,1}; int len = sizeof(input)/sizeof(input[0]); selectSort(input,len); output(input,len); }
程序运行结果:
标签:blog http os io ar for 2014 sp log
原文地址:http://blog.csdn.net/huojushou1128/article/details/39033111