# 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 [] = {, 0,-, 1 }; int Len = sizeof (input)/sizeof (input [0]); selectsort (input, Len); output (input, Len );}
Program running result:
Simple selection and sorting