資料結構學習堆疊

2021-09-08 21:48:44 字數 1763 閱讀 2131

走迷宮程式

原理是來自於《資料結構(c語言)》清華大學出版社關於堆疊的章節。

具體的實現**是自己寫的。

目前有一些還沒有完善的地方

1、不知道是為什麼處理時會出現地圖座標的x,y對調的情況。通過修改讀入和輸出的資訊糊弄過去orz。

2、不能成功查詢時,返回時空指標(設計時是這樣的),可是不能輸出notfound提示資訊。

3、迷宮地圖格式是(m*n)0~n,0~m。輸入是若要找第1行第11個塊則要輸入0 10 提示資訊。

4、地圖是反向的,比如說輸入的地圖資訊為1 0 1 在電腦裡是   1  1  1 .

1 1 1.                     1  0  1

#include #include enum distion;

typedef struct position

postype;

int map_cpy[100][100];//不可通過的路徑塊為0,可通過的為1

typedef struct mazemazetype;

typedef struct snode* stack;

typedef struct element

elementtype;

elementtype error;

typedef struct snode

;stack creatstack()//建立乙個空鍊錶,並且返回頭結點

int isempty(stack s)//探測棧是否是空,若為空則返回1,反之返回0

void push(elementtype item,stack s)//填裝棧

elementtype pop(stack s)//釋放棧頂元素

else

}void destroy(stack s)//銷毀乙個棧

free(s);

}stack clear(stack s)//清空乙個棧

s=null;

return s;

}long stacklength(stack s)//獲取棧的長度

return len;

}elementtype gettop(stack s)//獲得棧頂元素,不釋放棧頂

int pass(postype curpos)// 判斷能否通過該區域的函式

void footprint(postype curpos)//在map_cpy裡把當前位置的資訊留下

postype next(postype curpos,int di)

void markprint(postype nopass)

stack mazepath(mazetype maze,postype start,postype end)

else//當前區域不能通過的情況

if(e.di<4)}}

}while(!isempty(s));

return null;

}int main()

printf("please input start\n");

scanf("%d%d",&start.x,&start.y);

printf("please input end\n");

scanf("%d%d",&end.y,&end.x);

stack result=mazepath(map,start,end);

if(!isempty(result))

}else printf("notfound");

return 0;

}

資料結構學習之 堆疊

堆疊 順序儲存 define maxsize 10 typedef int elemtype struct stack 1.判斷堆疊是否為空 int emptyst struct stack s 2.判斷堆疊是否已滿的函式 int fullst struct stack s 3.元素入棧 void ...

資料結構學習筆記 堆疊

型別名稱 堆疊 stack 資料物件集 乙個有0個或多個元素的有窮線性表 操作集 長度為maxsize的堆疊s stack,堆疊元素item elementtype stack createstack int maxsize 生成空堆疊,最大長度maxsize int isfull stack s,...

資料結構 學習筆記 03 線性結構 堆疊

例子 計算機計算算術表示式。1.1 字尾表示式 字尾表示式策略 從左向右掃瞄,逐個處理運算數和運算符號。計算機實現字尾表示式計算方法的資料結構稱為堆疊。1.2 堆疊的抽象資料型別描述 堆疊 stack 具有一定操作約束的線性表。1 型別名稱 堆疊 2 資料物件集 乙個有0個或者多個元素的有窮線性表。...