typedef struct _st {
char Symbol;
struct _st* next;
}st;
st* stackTop = NULL;
void push(st* stackTop, char symbol);
int main(){
if (isOpenSymbol(expression[index])) {
push(stackTop, expression[index]);
symbolCount++;
}
}
void push(st* stackTop, char symbol) {
st* newNode = (st*)malloc(sizeof(st));
newNode->Symbol = symbol;
newNode->next = stackTop;
stackTop = newNode;
}
I'm trying to make checking balanced symbol program by using stack. This is part of the code. Push function creates newnode and stackTop points it. But when the function is finished the stackTop is initialized pointing NULL.
I tried that the function return newnode's address so stackTop point newnode like this.
stackTop = push(stackTop, expression[index].
When the push function is finished stackTop points newnode.
What is the difference between these and what am I missing?