91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .cpp
    金幣: 1
    下載: 1 次
    發(fā)布日期: 2021-11-13
  • 語言: C/C++
  • 標簽: 迷宮??

資源簡介

首先實現(xiàn)一個以鏈表作存儲結構的棧類型,然后編寫一個求解迷宮的非遞歸程序。求得的通路以 三元組(i,j,d)的形式輸出,其中(i,j)指示迷宮中的一個位置(行號和列號),d 表示走到下一 位置的方向(對于迷宮中任一位置,均有下、右、上、左四個方向來走出下一個位置,這四個方向可 分別編號為 1,2,3,4)。例如,對于下面測試數(shù)據(jù)給出的迷宮,輸出的一條通路為: (1,1,1),(2,1,1), (3,1,1),(4,1,1) ,(5,l,2),(5,2,2), (5,3,1),…。

資源截圖

代碼片段和文件信息

#include?
#include?
#define?overflow?-1?
#define?ok?1?
#define?error?0??
#define?STACK_INIT_SIZE??100?
#define?STACKINCREMENT?10?
typedef?int??Status;?
typedef?struct??
??{??int?x;??
?????int?y;??
??}PosType;//位置類型???
typedef?struct?
??{??int?rowcol;??
?????int?a[50][50];?
??}MazeType;//迷宮類型?????
typedef?struct?
??{??
????int?ord;//通道塊在路徑上的序號??
????PosType?seat;//通道塊在迷宮中的“坐標位置“??
????int?di;//從此通道塊走向下一個通道塊的方向???
??}SElemType;//棧的元素類型???
typedef?struct
??{??
????SElemType?*base;?
????SElemType??*top;??
????int?Stacksize;???
??}SqStack;//棧結構????
Status?InitStack(SqStack?&S)//初始化棧?
?{??
????S.base=(SElemType?*)malloc(STACK_INIT_SIZE*sizeof(SElemType));??
????if(!S.base)??exit?(overflow);??
????S.top=S.base;
????S.Stacksize=STACK_INIT_SIZE;??
return?ok;?
?}???
Status?Push(SqStack?&SSElemType?e)//入棧?
?{
???if(S.top-S.base>=S.Stacksize)??
????{?S.base=(SElemType*)realloc(S.base(S.Stacksize+STACKINCREMENT)*sizeof(SElemType));??????
???????if(!S.base)??exit?(overflow);???
???????S.top=S.base+S.Stacksize;???
???????S.Stacksize+=STACKINCREMENT;??
????}??
??????*S.top++=e;??
??????return?ok;?
?}???
Status?Pop(SqStack?&SSElemType?&e)//出棧?
{??if(S.top==S.base)?return?error;??
???e=*--S.top;??return?ok;
}???
bool?StackEmpty(SqStack?S)//判斷棧是否為空?
{??if(S.top==S.base)??
???return?ok;??
???else?return?error;?
}???
Status?InitMaze(MazeType?&maze)//初始化迷宮?
{??????int?ij;??????
????for(?j=0;j????????maze.a[0][j]=1;??
????for(?i=1;i????{???maze.a[i][0]=1;???
????????maze.a[i][maze.col+1]=1;?????????
????for(int?j=1;j????????scanf(“%d“&maze.a[i][j]);?
????}??????
????for(j=0;j????maze.a[maze.row+1][j]=1;???????????
????return?ok;?????
}//為了避免檢查邊界,把迷宮的外圍都設成障礙,迷宮的內核是row行,col列的數(shù)組?????
bool?Pass(MazeType?mazePosType?curpos)//判斷是否可以通過?
??{??return?maze.a[curpos.x][curpos.y]==0;??
??}??
Status?FootPrint(MazeType?&mazePosType?curpos)//留下足跡?
??{????
????maze.a[curpos.x][curpos.y]=2;???
????return?ok;?
??}???
SElemType?CreatElem(int?stepPosType?posint?di)//創(chuàng)造一個SElemType型的數(shù)據(jù)?
??{??SElemType?e;??
?????e.ord=step;??
?????e.seat=pos;??
?????e.di=di;??
?????return?e;?
??}???
bool?IsEnd(PosType?pos1PosType?pos2)//判斷是否結束?
?

評論

共有 條評論