#include
#include
#define MAX_LINE 5
#define MAX_LINE_LEN 81
/* 本部分代码功能建议:函数原型声明 */
/* User Code Begin(Limit: lines<=1, lineLen<=50, 考生可在本行后添加代码、最多行、每行长<=50字符) */
void sortP_Str(char *pstr[]);
/* User Code End(考生添加代码结束。注意:空行和单独为一行的{与}均不计行数、行长不计行首tab缩进) */
int main(void)
{
int i;
char *pstr[MAX_LINE], str[MAX_LINE][MAX_LINE_LEN];
for (i=0; i{
pstr[i] = str[i];
}
printf("Input 5 strings:\n");
for (i=0; i{
gets(pstr[i]);
}
sortP_Str(pstr);
printf("---------------------------\n");
for (i=0; i{
printf("%s\n", pstr[i]);
}
return 0;
}
/* User Code Begin(考生在此后完成自定义函数的设计,行数不限) */
void sortP_Str(char *pstr[])
{
int i,j;
char tmp[MAX_LINE_LEN];
int minid;
for(i=0;i{
minid=i;
for(j=i+1;j{
if(strcmp(pstr[j],pstr[minid])<0)
{
minid=j;
}
}
if(minid!=i)
{
strcpy(tmp,pstr[i]);
strcpy(pstr[i],pstr[minid]);
strcpy(pstr[minid],tmp);
}
}
}
这样子吗?
/*
Input 5 strings:
hello
My
Friend
are you ready?
help me!
---------------------------
Friend
My
are you ready?
hello
help me!
Press any key to continue
*/
void sortP_Str(char *pstr[MAX_LINE_LEN]) {
int i,j,k;
char tmp[MAX_LINE_LEN];
for(i = 0; i < MAX_LINE - 1; ++i) {
k = i;
for(j = i + 1; j < MAX_LINE; ++j)
if(strcmp(pstr[k],pstr[j]) > 0)
k = j;
if(k != i) {
strcpy(tmp,pstr[k]);
strcpy(pstr[k],pstr[i]);
strcpy(pstr[i],tmp);
}
}
}
void sortP_Str(char *pstr[])
{
int i=0,j=0;
char strTemp[MAX_LINE_LEN];
for(i=0;i
if(strcmp(pstr[j],pstr[j+1])>0)
{
strcpy(strTemp,pstr[j]);
strcpy(pstr[j],pstr[j+1]);
strcpy(pstr[j+1],strTemp);
}
}
}
看看是不是这个啊,那是系统写的,我看不懂 http://tieba.baidu.com/p/2357164568