//一个字符串数组按照字母序排序
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char * arr[]= {"hello", "world", "this", "is"};
int len = (sizeof(arr)/sizeof(char*));
int i,j;
for(i=0;i<len;i++)
{
for(j=0;j<len-1-i;j++)
{
if((arr[j][0] - arr[j+1][0]) > 0 )
{
char *temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for(int n=0;n<len;n++)
{
cout<<arr[n]<<endl;
}
return 0;
}
字符串数组按照字母序排序(C++)
最新推荐文章于 2024-07-25 09:47:19 发布