一天一个算法:用指向指针的指针的方法对5个字符串排序并输出
////////////////////////////////////////////////////////////////////////// //用指向指针的指针的方法对5个字符串排序并输出。 // // ////////////////////////////////////////////////////////////////////////// void sort(char **str){ char *p=0; for (int i=0;i<4;i++) { for (int j=i+1;j<5;j++) { if (strcmp(*(str+i),*(str+j))<0) { p=*(str+i); *(str+i)=*(str+j); *(str+j)=p; } } } } void pSort() { char *str[5]; int i=0; cout<<"please input 5 num:"<<endl; for (i=0;i<5;i++) { str[i] = new char[50]; cin.getline(*(str+i),50); } sort(str); cout<<"sort:"<<endl; for (i=0;i<5;i++) { cout<<*(str+i)<<endl; } }