C++如何对数字开头的字符串进行排序

2025-03-20 09:45:20
推荐回答(1个)
回答1:

VC6.0下编译运行,结果无误。

#include
#include
using namespace std;

void temp(char *str[])
{
for (int i=0; i<5; i++)
{
for (int j=1; j<5-i; j++)
{
if ( strcmp(str[j-1],str[j]) > 0 )
{
char *tmp = str[j-1];
str[j-1] = str[j];
str[j] = tmp;
}
}
}
}

int temp1(char *p,char *str[])
{
for (int i=0; i<5; i++)
{
if ( strcmp(p,str[i]) == 0 )
{
return 1;
}
}
return 0;
}

void main()
{
char *str[5]={"abcde","xfghek","dfjdsiei","nice","zfdd"};
temp(str); //调用排序函数
cout<<"按序结果:"<for (int i=0; i<5; i++)
{
cout<}
char *p = "nice";
cout<}