- 1、本文档共9页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
迷宫最最短路径
迷宫最最短路径#include iostream
#include stdlib.h
#include stdio.h
#include string.h
int H, W;
int **map;
using namespace std;
struct PosType
{
int x;
int y;
};
/*struct ElemType
{
int ord;
PosType seat;
int di;//1,2,3,4分别代表E, S, W, N;
};*/
typedef struct Node
{
struct Node *next;
struct Node *prior;
PosType seat;
}*Link;
struct Stack
{
Link head;
int len;
};
void InitStack(Stack stack)
{
stack.len = 0;
stack.head = (Link)malloc(sizeof(Link));
if(!stack.head)
exit(1);
stack.head-next = NULL;
stack.head-prior = NULL;
}
void Push(Stack stack, PosType seat)
{
Link p;
p = new Node;
p-seat = seat;
p-next = stack.head-next;
if(stack.head-next)//注意下一个是否为空
stack.head-next-prior = p;
stack.head-next = p;
p-prior = stack.head;
}
bool Pop(Stack stack, PosType seat )
{
Link p;
p = stack.head-next;
if(p)
{
seat = p-seat;
stack.head-next = p-next;
if(p-next)
p-next-prior = p-prior;
free(p);
return true;
}
return false;
}
bool GetTop(Stack stack, PosType seat)
{
if(stack.head-next)
{
Link p = stack.head-next;
seat = p-seat;
return true;
}
return false;
}
void PrintSeat(PosType data)
{
printf(%d %d , data.y, data.x);
}
void StackTraverse(Stack stack, void(*visit)(PosType))
{
Link p, q;
for(q = stack.head-next; q-next; q = q-next);
for(p = q; p-prior; p = p-prior)
{
visit(p-seat);
}
//printf(\n);
}
//==============the defination of queue=================
struct Queue
{
Node *front;
Node *rear;
};
void InitNode(Node p)
{
p.next = NULL;
}
void InitQueue(Queue Q)
{
Node *node = (Node *)malloc(sizeof(Node));
InitNode(*node);
Q.front = node;
Q.rear = node;
}
void EnQueue(Queue Q, PosType seat)
{
Link q;
q = (Node *)malloc(sizeof(Node));
if(!q)
exit(1);
InitNode(*q);//because we insert it at t
文档评论(0)