So I have the function top() to return the top of the a stack (implemented as a linked list). It returns a Node struct. I am getting errors when I try to access the variables of the returned struct.
typedef struct nodeStrcut{
int x,y;
struct nodeStrcut* next;
}Node;
Node top(Node** head){
return **head;
}
void push(Node** head, int x, int y){
//create a new node to contain the value
Node* newPtr = (Node*) malloc(sizeof(Node));
newPtr->x = x;
newPtr->y = y;
newPtr->next = *head;
*head = newPtr;
}
int main(int argc, char **argv){
Node* stack;
stack = NULL;
push(&stack, 3, 3);
push(&stack, 2, 3);
push(&stack, 3, 5);
printf("Node value: %d, %d\n", (pop(&stack)).x, (pop(&stack)).y);
return -1;
}
And then I get the following error:
project.c: In function ‘main’:
error: request for member ‘x’ in something not a structure or union
error: request for member ‘y’ in something not a structure or union
I know that I could use stack->x to get values but I need to have a function that returns value from the stop of the stack. Help would be appreciated.