Bidirectional Dereferencing Challenge

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.

+5
source share
2

-> , , , stack->value, ->, * - . :

int popped_value = (*stack)->value;
*stack = (*stack)->next;

, wallyk , :

struct Element *sip = *stack;
int popped_value = sip->value;
*stack = sip->next;
+8

-> , (*) :

*stack->next

:

*(stack->next)

, stack->next .

:

(*stack)->next

.

+6

All Articles