代码块:
#include <iostream> using namespace std; void input(char **word, int n); void output(char **word, int n); void sort(char **word, int n); int main() { char *word[10]; input(word, 10); sort(word, 10); output(word, 10); system("pause"); return 0; } void input(char **word, int n){ cout<<"Enter "<<n<<" words: "; for(int i=0; i<n; i++){ word[i]=new char[20]; cin>>word[i]; } } void sort(char **word, int n){ char **p, **q, *temp; for(p=word; p<word+n; p++){ for(q=p+1; q<word+n; q++){ if(**p==**q) *q="\0"; else if(**p>**q){ temp=*p; *p=*q; *q=temp; } } } } void output(char **word, int n){ int i; cout<<"Output: "; for(i=0; i<n; i++){ if(word[i]=="\0") continue; cout<<word[i]<<" "; free(word[i]); } cout<<endl; }