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

来源:互联网 发布:php http上传文件 编辑:程序博客网 时间:2024/05/22 07:41

void  sortStr(char *p[],int count){

   for (int i =0; i < count -1; i++) {

       for (int j =0; j< count - i - 1; j++) {

           if (strcmp(*(p + j), *(p + j +1))>0) {//判断字符串的

               char * temp = *(p+j);

                *(p + j) = *(p + j +1);

                *(p + j +1) = temp;

            }

        }

    }

   for (int i =0; i < 10; i++) {

       printf("%s\n",*(p + i));

    }

}

int main(int argc,const char * argv[])

{


    char *str[10] ={"hello","apple","iPhon","lanou","henan","beiji","shang","qunim","manac","zhaoc"};

   sortStr(str,10);


 return 0;

}



0 0
原创粉丝点击