本區搜索:
Yahoo!字典
打印

[ICT] 關於Stack的問題

think of a stack is a container, push is put thing into it, pop is take out thing from it.

take (A) as example
sequence -- stack -- output (when pop)
push 1 -- |1|X|X|X|X|X| -- n/a
push 2 -- |1|2|X|X|X|X| -- \ /
push 3 -- |1|2|3|X|X|X| -- \ /
pop -- |1|2|X|X|X|X| -- 3
pop -- |1|X|X|X|X|X| -- 3,2
pop -- |X|X|X|X|X|X| -- 3,2,1
push 4 -- |4|X|X|X|X|X| -- \ /
pop -- |X|X|X|X|X|X| -- 3,2,1,4
push 5 -- |5|X|X|X|X|X| -- \ /
pop -- |X|X|X|X|X|X| -- 3,2,1,4,5
push 6 -- |6|X|X|X|X|X| -- \ /
pop -- |X|X|X|X|X|X| -- 3,2,1,4,5,6

to understand it , try it on (C) and (D) as your self exercises ,
finally try your best on (B) as it is impossible to have a sequence .

[ 本帖最後由 tony625 於 2014-1-18 09:29 PM 編輯 ]
   

TOP

[隱藏]
you got it

TOP

重要聲明:小卒資訊論壇 是一個公開的學術交流及分享平台。 論壇內所有檔案及內容 都只可作學術交流之用,絕不能用商業用途。 所有會員均須對自己所發表的言論而引起的法律責任負責(包括上傳檔案或連結), 本壇並不擔保該等資料之準確性及可靠性,且概不會就因有關資料之任何不確或遺漏而引致之任何損失或 損害承擔任何責任(不論是否與侵權行為、訂立契約或其他方面有關 ) 。