若一個空的堆疊(stack)依序執行下列指令後,push(x)、push(x)、pop()、push(y)、push(x)、push(y)、pop()、push(x),則堆疊內的資料由上(top)到下(bottom)的排列為何?
Axyxx
Bxxyx正確答案
Cyxyx
Dxyxy
答案與詳解
模擬:push x→[x];push x→[x,x];pop→[x];push y→[x,y];push x→[x,y,x];push y→[x,y,x,y];pop→[x,y,x];push x→[x,y,x,x]。由頂到底為 x,x,y,x。
