指针数组-字符串排序

将字符串排序输出

#include
#include 
#include
using namespace std;
int main()
{
    int i,k,j;
    static char *str[4]={"Program","Fortran","C","Basic"};
    for(i=0;i<4;i++)
        for(j=i+1;j<4;j++)
        if(strcmp(str[i],str[j])>0)
    {
        char *temp;
        temp=str[j];
        str[j]=str[i];
        str[i]=temp;
    }
    for(i=0;i<4;i++)
        cout<

字符串是按照ASCII码排列的

实际上交换的是指针的指向,通过改变指针的指向变化后按照指针数组下标的顺序输出,比二维数组中改变字符串的位置要方便的多

你可能感兴趣的:(指针数组-字符串排序)