I'm having a bit of a problem with pushing an item onto a stack.
Could anyone help me to figure out whats going on here?Code:void push( StackNodePtr *topPtr, char value ){
//Push a value on the stack.
StackNode top; //Create node
top.data = value; //Put data in top
StackNode *Snode = &topPtr; //make Snode point to topPtr
top.nextPtr = &Snode; //Make top point to Snode
topPtr = ⊤ //make topPtr(head) point to top.
}
Is it because I'm pointing to topPtr so when the value changes in topPtr, so would Snode and therefore top would change too?
This is the code for the Stack struct
Thanks for your time :)Code:struct stackNode {
char data;
struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;