看板 java 關於我們 聯絡資訊
剛剛在看Cracking the Coding Interview 發現他的程式有一個小錯 他是這樣寫的 class Stack{ Node top; Object pop(){ if (top != null){ Node item = top.data; top = top.next;                ^^^^^^^^^        return item; } return null; } void push(Object item){ Node t = new Node(item); t.next = top; top = t; } Object peek(){ return top.data; } } ........................ 在 pop()這個方法裡,top.data 依照書中class Node裡的data型態是int 所以Node item 不應該等於top.data 應該要改成 Node item = top; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 135.0.163.188 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1428864138.A.1CF.html ※ 編輯: yule1224 (135.0.163.188), 04/13/2015 02:43:36
pttworld: 未找資料,但應該就是你所講的= top; 推個。 04/13 03:11