求问大神,程序的可读性是个什么概念?如何提高程序的可读性?
我自己写出来的程序,我都看不懂了,天啊,我当时是怎么写出来的......#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;
}
只记得这是一道要走迷宫的题.....我觉得我这样的版面应该。。没有什么问题吧?