数据结构:栈应用_求解迷宫问题3

/************************************************************************/

/* 数据结构:栈应用:求解迷宫问题                                                                   */

/* 挑灯看剑-shuchangs@126.com 2010-10                                                             */

/* 云歌国际(Cloud Singers International www.cocoral.com                          */

/************************************************************************/

//上接版面 《数据结构:栈应用:求解迷宫问题2》

void printMzePath(Stack S, int (*mtx)[9], int m, int n)

{

       Status StackLocate(Stack S, int x, int y, NodePointer rtnNode);

       COUNT i, j;

       Node N =

       {

              NULL, NULL, NULL

       };

       printf("矩阵信息:%d行,%d列!\n", m, n);

       if (!StackIsEmpty(S))

       {

              for (i = 0; i < m; i++)

              {

                     printf("row=%d   ", i);

                     for (j = 0; j < n; j++)

                     {

                            if (StackLocate(S, i, j, &N))

                                   printf(" %c ", '*');

                            else

                                   printf(" %d ", *(*(mtx + i) + j));

                     }

                     printf("\n");

              }

       }

       else

       {

              for (i = 0; i < m; i++)

              {

                     printf("row=%d   ", i);

                     for (j = 0; j < n; j++)

                     {

                            printf(" %d ", *(*(mtx + i) + j));

                     }

                     printf("\n");

              }

       }

}

 

Status StackLocate(Stack S, int x, int y, NodePointer rtnNode)

{

       COUNT i = 0;

       COUNT n = S.len;

       NodePointer p = S.base;

       Status status = ERROR;

       for (i = 0; i < n; i++)

       {

              if (p->data.x == x && p->data.y == y)

              {

                     rtnNode = p;

                     status = OK;

                     break;

              }

              else

              {

                     p = p->next;

              }

       }

       if (p == NULL)

       {

              status = ERROR;

       }

       return status;

}

 

运行测试结果如下

 

矩阵信息:9行,9列!

row=0    0  0  0  0  0  0  0  0  0

row=1    0  *  1  0  1  1  0  1  0

row=2    0  1  1  0  1  1  0  1  0

row=3    0  1  1  1  1  0  1  1  0

row=4    0  1  0  0  0  1  1  1  0

row=5    0  1  1  0  0  1  0  1  0

row=6    0  1  0  1  1  1  0  1  0

row=7    0  1  1  1  1  0  0  1  0

row=8    0  0  0  0  0  0  0  0  0

迷宫求解结束!

栈长度:21

打印结点信息(栈底到栈顶):

[1] foot[1][1] = 1

[2] foot[1][1] = 1

[3] foot[1][2] = 1

[4] foot[2][2] = 1

[5] foot[3][2] = 1

[6] foot[3][1] = 1

[7] foot[4][1] = 1

[8] foot[5][1] = 1

[9] foot[6][1] = 1

[10] foot[7][1] = 1

[11] foot[7][2] = 1

[12] foot[7][3] = 1

[13] foot[7][4] = 1

[14] foot[6][4] = 1

[15] foot[6][5] = 1

[16] foot[5][5] = 1

[17] foot[4][5] = 1

[18] foot[4][6] = 1

[19] foot[4][7] = 1

[20] foot[5][7] = 1

[21] foot[6][7] = 1

矩阵信息:9行,9列!

row=0    0  0  0  0  0  0  0  0  0

row=1    0  *  *  0  1  1  0  1  0

row=2    0  1  *  0  1  1  0  1  0

row=3    0  *  *  1  1  0  1  1  0

row=4    0  *  0  0  0  *  *  *  0

row=5    0  *  1  0  0  *  0  *  0

row=6    0  *  0  1  *  *  0  *  0

row=7    0  *  *  *  *  0  0  1  0

row=8    0  0  0  0  0  0  0  0  0

Press any key to continue

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值