本帖最後由 passerby 於 2010-12-10 00:53 編輯
Stack 有咩用, 有咩 application
點解唔用 array?
點解要係 last in , first out, 唔係first in , first o ...
gandalf_Zoro 發表於 2010-12-9 20:34 
用wikipedia or google,你會查到 stack定義,想像stack係個桶,入資料入去push,取資料係pop,最頂資料係last入,所以咪 Last In First Out。array 只係連續資料結構,沒有規定只係由頭尾先處理。
Queue 係 stack方式o既相反,First-In-First-Out,先入資料,先處理,現實例子: 巴士排隊、printer jobs queue。
stack 結構用途:倒序處理,先處理最後輸入資料
stack 應用:
概括類型
- Expression evaluation and syntax parsing
- 現實上任何 nested or recursive function call 都係stack結構,事實寫 recursive function機會比用 stack library高好多,很多問題都依賴 recursive 方式去解決。
- Backtracking
- Shortest Path Problem
個別問題
- maze problem (老鼠走迷宮)
- 8-puzzle Problem
- N-Queen Problem
- Knapsack Problem
refs:
http://mmdays.com/2008/04/03/stack/
http://www.csie.ntnu.edu.tw/~u91029/Backtracking.html |