| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5968 人关注过本帖
标题:求问大神,程序的可读性是个什么概念?如何提高程序的可读性?
取消只看楼主 加入收藏
超电磁场
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2016-10-3
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:0 
求问大神,程序的可读性是个什么概念?如何提高程序的可读性?
我自己写出来的程序,我都看不懂了,天啊,我当时是怎么写出来的......
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    int map[5][5];
    int visit[5][5];
    int pre[100];  
    struct node
    {
        int x;
        int y;
    }list[100];
    int dir[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
    int go(int x, int y)
        {
            if (0 <= x&&x<5 && 0 <= y&&y<5 && map[x][y] == 0)
                return 1;
            return 0;
        }
    void print(int x)
        {
            int t;
            t = pre[x];
            if (t == 0)
                {
                    printf("(0, 0)\n");
                    printf("(%d, %d)\n", list[x].x, list[x].y);
                    return;
                }
            else
                print(t);
            printf("(%d, %d)\n", list[x].x, list[x].y);
        }
    void bfs()
        {
            int i, head, tail;
            int x, y, xx, yy;
            memset(visit, 0, sizeof(visit));
            head = 0;
            tail = 1;
            list[0].x = 0;
            list[0].y = 0;
            pre[0] = -1;
            while (head<tail)
                {
                    x = list[head].x;
                    y = list[head].y;
                    if (x == 4 && y == 4)
                        {
                            print(head);
                            return;
                        }
                    for (i = 0; i<4; i++)
                        {
                            xx = x + dir[i][0];
                            yy = y + dir[i][1];
                            if (!visit[xx][yy] && go(xx, yy))
                                {
                                    visit[xx][yy] = 1;
                                    list[tail].x = xx;
                                    list[tail].y = yy;
                                    pre[tail] = head;
                                    tail++;
                                }
                         }
                    head++;
                }
            return;
            }
    int main()
        {
            int i, j;
            for (i = 0; i<5; i++)
                for (j = 0; j<5; j++)
                scanf("%d", &map[i][j]);
            bfs();
            return 0;
        }

只记得这是一道要走迷宫的题.....我觉得我这样的版面应该。。没有什么问题吧?
2016-10-12 22:17
快速回复:求问大神,程序的可读性是个什么概念?如何提高程序的可读性?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024550 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved