void printArr(const char ** p, int len){
for(int i = 0; i < len; ++i){
cout << p[i] << endl;
}
}
void sortSelect(const char ** p, int len){
for(int i = 0; i < len - 1; ++i){
int max = i;
for(int j = i + 1; j < len; ++j){
if(p[j] > p[max]){
max = j;
}
}
// 交换
if(i != max){
const char* tmp = p[i];
p[i] = p[max];
p[max] = tmp;
}
}
}
int main()
{
const char* arr[] = {"aa", "bb", "cc", "dd", "ee"};
int len = sizeof(arr) / sizeof(char*);
cout << len << endl;
printArr(arr, len);
sortSelect(arr, len);
cout << "----------------" << endl;
printArr(arr, len);
return 0;
}
输出:
5
aa
bb
cc
dd
ee
----------------
ee
dd
cc
bb
aa