单向链表在栈中的存储
typedef struct StackNode {SElemType data;struct StackNode* next;
}StackNode, *LinkStack;
LinkStack S;
//链栈初始化
void InitStack(LinkStack& S)
{S = NULL;return OK;
}
//判断链栈是否为空
Status StackEmpty(LinkStack S)
{if (S = NULL) return TRUE;else return FALSE;
}
//节点入栈
Status Push(LinkStack& S, SElemType e)
{p = new StackNode;p->data = e;p->next = S;S = p;return OK;
}
//节点的出栈
Status Push(LinkStack& S, SElemType &e)
{if (S==NULL){return ERROR;}LinkStack p = new StackNode;e = p->data;p = S;S = S->next;delete p;return OK;
}