64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cstring>
using namespace std;
void Panxu(char *str[20],int n)
{
//char *p;
for (int m=0;m<n-1;m++)
{
for (int i=0;i<n-m-1;i++)
{
if (strcmp(str[i],str[i+1])>0)
{
char *p = new char[20];
strcpy(p, str[i]);
strcpy( str[i], str[i+1]);
strcpy(str[i+1], p);
}
}
}
}
void main()
{
int n, i;
cout<<"输入字符串数目n:"<<endl;
cin>>n;
char *p[20];
for (i=0;i<n;i++)
{
cout<<"输入字符串"<<endl;
p[i] = new char[100];
cin>>p[i];
}
Panxu(p,n);
for (i=0;i<n;i++)
{
cout<<p[i]<<endl;
}
}