堆疊,也可直接稱棧,是一種特殊的序列形式的資料結構,它的特殊之處在於只能允許在鏈結序列或陣列的一端進行加入資料和輸出資料的運算。另外堆疊也可以用一維陣列或鏈結序列的形式來完成。
1#define stack_init_size 100
2#define stackincrement 10
34 typedef struct
5 sqstack;910
int initstack(sqstack &s)
1118
//棧頂插入
19int push(sqstack &s,int
e)
2028 *s.top++ =e;
29return1;
30}31int pop(sqstack &s,int &e)
32
迷宮求解問題實現:
1//2//34 #include "
stdafx.h
"5 #include "
stdio.h
"6 #include "
stack.h
"7 #include "
malloc.h"8
9#define range 10 //
設定陣列的最大長度
1011
12 typedef int
directtype;
1314 typedef struct
postype;
1718 typedef struct
mazetype;
2223
24 typedef struct
elemtype; //
棧的元素型別
2930
31 typedef struct
nodetype nodetype,*linktype; //
結點型別,指標型別
3536 typedef struct
stack; //
棧型別
4041
42void
initialization()
4748
void makenode(linktype &p,elemtype e)
55 //標記走過的節點
56void footprint(mazetype &maze,postype curpos)
5960
int pass(mazetype &maze,postype curpos)
6566
6768
void createmaze(mazetype &maze)
91}
92 //標記四個方向都走不通的節點
93void makeprint(mazetype &maze,postype curpos)
9697
98void nextpos(postype &curpos,directtype di)
105}
106107
108109
void
printmaze(mazetype maze)
115 printf("\n"
);
116}
117118
119120
intmazepath(mazetype maze,postype start,postype end)//
else
138 }//
if
139else
140if (!stackempty(s))//
while
147if(e.di<4
)//if
152 }//
if
153 }while(!stackempty(s)&&!found);
154return
found;
155 }//
mazepath
HTML快速回顧
是用來描述網頁的語言 hyper text markup language 是標記語言不是程式語言,用一套標記標籤來描述網頁。開始標籤 html元素 結束標籤 htm html 到 h1是主標題 最重要的 瀏覽器會自動在段落前後新增空行,是塊級元素 鏈結可以是字 句子 影象。href規定鏈結的目標,...
演算法快速回顧 排序演算法
常用排序演算法有以下幾種 氣泡排序 插入排序 快速排序 歸併排序 堆排序。本文將對五種常用演算法分析並實現。交換兩個元素的值 這裡列出幾種不同寫法 void swap int a,int b void swap int a,int b void swap int a,int b 氣泡排序 原理 比較...
java web 聽器快速入門 快速回顧
採用的是觀察者模式 觀察物件的變化。分類 監聽 三大域 生命週期監聽 servletcontextlistener,它有兩個方法,乙個在出生時呼叫,乙個在死亡時呼叫 void contextinitialized servletcontextevent sce 建立servletcontext時 v...