迷宮的基本操作

2021-08-28 23:14:58 字數 3233 閱讀 6933

maze.h

#pragma once

#include

#include

"stack.h"

#define max_row 6

#define max_col 6

typedef

struct position

position;

typedef

struct maze

maze;

void

initmap

(maze* m,

int map[max_row]

[max_col]);

void

printmap

(maze* m)

;void

passmap

(maze* m, position enter, stack* s)

;//走迷宮

void

passmaprec

(maze * m, position enter)

;//走迷宮,遞迴走法

int_passmaze

(maze* m, position entry, position cur)

;//輔助遞迴

intisvalidenter

(maze* m, position enter)

;//檢測迷宮的入口是否有效

intismazeexit

(maze* m, position cur, position enter)

;//檢測cur的位置是否為迷宮的出口

intispass

(maze* m, position cur)

;//檢測該位置是否通路

void

printpath

(stack* s)

;//列印走過的路徑

maze.c
#include

"maze.h"

void

initmap

(maze * m,

int map[max_row]

[max_col]

)for

(i =

0; i < max_row; i++)}

}void

printmap

(maze * m)

for(i =

0; i < max_row; i++

)printf

("\n");

}}void

passmap

(maze * m, position enter, stack * s)

//2.取棧頂位置cur->走cur位置->檢測cur是否為出口(i***it( ),是出口->返回)

//先檢測next位置是否可以走通

//可以走通->儲存當前路徑

stackpush

(s, enter)

;while

(stackempty

(s))

//上 next = enter;

next.x -=1

;if(ispass

(m, next)

)//左

next = cur;

next.y -=1

;if(ispass

(m, next)

)//右

next = cur;

next.y +=1

;if(ispass

(m, next)

)//下

next = cur;

next.x +=1

;if(ispass

(m, next)

)//說明cur步走錯了->重新標記->出棧

m->map[cur.x]

[cur.y]=3

;stackpop

(s);}}

void

passmaprec

(maze * m, position enter)

_passmaze

(m, enter, enter);}

intisvalidenter

(maze * m, position enter)

//保證入口一定在邊界if(

0== enter.x || max_row -

1== enter.x ||

0== enter.y || max_col -

1== enter.y)

return0;

}int

ismazeexit

(maze * m, position cur, position enter)

if(cur.x ==

0|| cur.x == max_row -

1|| cur.y ==

0|| cur.y == max_col -1)

return0;

}int

ispass

(maze * m, position cur)

void

printpath

(stack * s)

<---"

, top.x, top.y)

;stackpop

(s);

}//這時列印最後乙個元素

position top =

stacktop

(s);

printf(""

, top.x, top.y);}

int_passmaze

(maze * m, position entry, position cur)

//上 next = cur;

next.x -=1

;if(_passmaze

(m, entry, next)

)//左

next = cur;

next.y -=1

;if(_passmaze

(m, entry, next)

)//右

next = cur;

next.y +=1

;if(_passmaze

(m, entry, next)

)//下

next = cur;

next.x +=1

;if(_passmaze

(m, entry, next)

) m->map[cur.x]

[cur.y]=3

;}return0;

}

的基本操作

命令模式 不可以輸入內容,只能使用命令,進入vi的預設模式 插入模式 可以輸入內容 最底行模式 游標停在最底行,如儲存檔案 命令模式切換到插入模式 按鍵效果 插入到游標所在位置的前邊 a插入到游標所在位置的後邊 o插入到游標所在行的下一行 i插入到游標所在行的行首 a插入到游標所在行的行尾 o插入到...

的基本操作 Linux 基本操作命令總結

每日17點準時技術乾貨分享 linux 基本操作命令 檔案和目錄管理 建立和刪除 建立 mkdir 刪除 rm 刪除非空目錄 rm rf file 目錄 刪除日誌 rm log 等價 find name log exec rm 移動 mv 複製 cp 複製目錄 cp r 建立檔案 touch 檢視 ...

棧的基本應用 求迷宮的路徑

include stdafx.h typedef structcoordinate typedef struct item define maze line 10 define maze row 9 int a maze row maze line int mark maze row maze li...