#include <stdio.h>
#include <stdlib.h>
typedef struct treeNode *BinTree;
typedef struct stackNode *Stack;
struct treeNode
{
int data;
struct treeNode *left;
struct treeNode *right;
};
struct stackNode
{
BinTree node;
struct stackNode *next;
};
Stack createStack(){
Stack stack = (Stack)malloc(sizeof(struct stackNode));
stack->next = NULL;
return stack;
}
int stackIsEmpty(Stack stackTop){
if (stackTop->next)
return 0;
return 1;
}
void stackPush(Stack stackTop, BinTree myNode){
if (myNode)
{
Stack midNode = (Stack)malloc(sizeof(struct stackNode));
midNode->node = myNode;
midNode->next = stackTop->next;
stackTop->next = midNode;
}
}
BinTree stackPop(Stack stackTop){
if (stackIsEmpty(stackTop))
{
printf("Stack is empty!\n");
return NULL;
}
BinTree mid = stackTop->next->node;
Stack willFree = stack