看板 Grad-ProbAsk 關於我們 聯絡資訊
※ 引述《st84514 (綜合水果武士)》之銘言: : 題目如下: : Describe how one can use stacks and the push & pop operations to simulate an : arrays retrieval and storing operations, respectively : 大概了解題目的意思也有寫出自己的答案可是不知道對不對... : 有請高手解題!謝謝!! 不敢說是高手 可是有點想法 想看看跟原po想的有什麼差別 XD" 用兩個stack B C 來implement array A //assume array A : 1 ~ n ; retrieval (array A[i]){ if (top_B < i){ return -1 ; //A[i]不存在 } else { while ( 1 ){ if (0 == top_B - i){ return pop(B); } push(C,pop(B)); } while (0 != top_C){ push(B,pop(C)); } } } stroing (array A, element item){ push (A,item); } 大家有什麼看法嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.236.86
skill91002:我也覺得是這樣耶 只是教授會說"stroing"查無此字 扣分 12/18 08:22
skill91002:另外while(1)裡面如果return了下面會繼續做嗎??太久沒 12/18 08:23
skill91002:碰程式了XD 要是我就用algorithm的描述了 怕細節被扣光 12/18 08:24
christianSK:return 就結束了阿 12/19 10:33