在主函数中输入10个等长的字符串。用另一函数对他们排序。然后在主函数输出这10个已经排好许的字符串。

 

 
  
  1. #include<iostream>  
  2. #include<string>  
  3. #include<iomanip>  
  4. using namespace std;  
  5.  
  6. int main()  
  7. {    const int n=10;  
  8.      string str[n];  
  9.   void sort(string *p,int n);  
  10.       int i,j;  
  11.   for(i=0;i<n;i++)  
  12.    cin>>str[i];  
  13.      sort(str,n);  
  14.   for(i=0;i<n;i++)  
  15.     
  16.   cout<<str[i]<<endl;  
  17.  
  18.  
  19. }  
  20.  void sort(string *p,int n)  
  21.  {  
  22.      string temp,*str,*i;  
  23.      str=p;  
  24.   int j,k;  
  25.   for(str=p;str<p+n-1;str++)  
  26.   {  
  27.    for(i=str+1;i<p+n;i++)  
  28.          if(*str>*i)  
  29.    { temp=*str;  
  30.           *str=*i;  
  31.     *i=temp;  
  32.        }  
  33.   }  
  34.  }  
  35.