十字星递归算法

来源:互联网 发布:c语言goto语句的用法 编辑:程序博客网 时间:2024/04/29 16:06

十字星递归算法(OK,我也不知道这叫什么图形,姑且就叫十字星吧):

void shizixing(int starti,int temp,int endi) //starti:起始数字,temp:临时存储终止数字,endi:终止数字{    if(endi>starti)    {        shizixing(starti,temp,--endi);        int si=starti;        int it=temp+starti-endi-1;        while (si<=temp)        {            printf("%d",si<it?si:it);            ++si;        }        --si;        while(--si>=starti)        {            printf("%d",si>it?it:si);        }        printf("\n");    }else if(endi<starti)    {        if(starti-1!=endi)        shizixing(--starti,temp,endi);        else --starti;        int si=endi;        while (si<=temp)        {            printf("%d",si<starti?si:starti);            ++si;        }        --si;        while(--si>=endi)        {            printf("%d",si>starti?starti:si);        }        printf("\n");    }else    {        shizixing(temp,temp,endi);        int si=endi;        while (si<=temp)        {            printf("%d",si);            ++si;        }        --si;        while(--si>=starti)        {            printf("%d",si);        }        printf("\n");    }}

十字星图片

0 0
原创粉丝点击