?? 字符串排序.cpp
字號:
#include<iostream.h>
#include<string.h>
void main(){
char s[5][20]={"CAUC","Sichuan","China","enterprise","visualc++"};
char (*p)[20]; //定義行指針
p=s;
int i,j,k;
cout <<"排序前:"<< endl;
for(k=0;k<5;k++)
cout << s[k] << endl;
char ts[20];
char c;
for(k=0;k<5;k++)
for(i=0;i<strlen(s[k])-1;i++)
for(j=i+1;j<strlen(s[k]);j++)
{
if(s[k][i]>s[k][j])
{
c=*(*(p+k)+i );//s[k][i];
*(*(p+k)+i)=*(*(p+k)+j);//s[k][i]=s[k][j];
*(*(p+k)+j)=c;//s[k][j]=c;
}
}
for(i=0;i<4;i++)
for(j=i+1;j<5;j++)
if(strcmp(*(p+i),*(p+j))>0)//if(strcmp(s[i],s[j])>0)
{
strcpy(ts,*(p+i));//strcpy(ts,s[i]);
strcpy(*(p+i),*(p+j));//strcpy(s[i],s[j]);
strcpy(*(p+j),ts);//strcpy(s[j],ts);
}
cout <<"\n排序后:"<< endl;
for(i=0;i<5;i++)
{
cout<<*p<<endl;
p++;
}
cout << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -