You may try a more sanitized wording, to help you understand better what your are trying to achieve.
Perhaps something along the following lines...
Code:
typedef struct TreeNode TreeNode;
struct TreeNode{
int val;
TreeNode *left;
TreeNode *right;
};
typedef struct StackNode StackNode;
struct StackNode {
TreeNode *treenode;
StackNode *prev;
};
/* this is not really needed, but I followed your example */
typedef struct Stack Stack;
struct Stack {
int nelems;
StackNode *top;
};
Please note that forward declarations with typedef's are optional in your case (for example, it's not that you are implementing a library with opaque objects), but they help in writing shorter code later on.
Then define the basic operations for your stack. For example...
Code:
void stack_push( Stack *stack, const TreeNode *treenode );
TreeNode *stack_pop( Stack *stack );
int stack_empty( const Stack *stack );
void stack_destroy( Stack *stack );
Finally define your stack, lets say...
Code:
...
int main( void )
{
Stack s = {0, NULL};
...
and you should be good to go.
PS. Btw, hi everybody, this is my first post in the forum.