I would like to implement a stack using a linked list.
To implement pop () for my stack, I call a double pointer (pointer to a pointer), which (eventually) points to the top of my stack (the first entry in the linked list).
The reason I'm doing this is because the caller can maintain a static stack pointer.
My related list item is struct:
struct Element {
int value;
struct Element *next;
};
pop ():
int pop (struct Element **stack) {
int popped_value = *stack->value;
*stack = *stack->next;
return popped_value;
}
The problem I have is trying to dereference the double pointer stack **. This code generates the following error:
error: request for member βvalueβ in something not a structure
error: request for member βnextβ in something not a structure
In my opinion, the value * stack-> or ** stack.value should work to fetch popped_value, but I get an identical error.
source
share