我想用鏈表實現堆棧。爲了實現我的棧的pop(),我讓調用者傳遞一個雙指針(指針指向)(最終)指向我堆棧的頂部(鏈表中的第一個條目)。解決雙引號問題
我這樣做的原因是因爲這樣調用者可以保持一個靜態指針到堆棧。
我的鏈表元素結構:
struct Element {
int value;
struct Element *next;
};
pop()方法實現:
int pop (struct Element **stack) {
int popped_value = *stack->value;
*stack = *stack->next;
return popped_value;
}
我有問題試圖取消引用雙指針**堆棧。此代碼生成以下錯誤:
error: request for member ‘value’ in something not a structure
error: request for member ‘next’ in something not a structure
在我的腦海裏,無論是*重新建立了新>值或** stack.value應該努力找回popped_value,但我得到了相同的錯誤。
只要使用好醇'堆棧 - >下一個' – Kapichu