typedef struct StackNode {
int data;
struct StackNode *next;
}StackNode,*LiStack;
/初始化
void InitStack(LiStack &S) {
S = NULL;
}
void Push(LiStack &S,int x) {
StackNode *p = new StackNode;
p->data = x;
p->next = S;
S = p;
}
bool Push(LiStack &S,int &x) {
if(S==NULL)
return false;
x = S->data;
StackNode *p = new StackNode;
p = S;
S = S->next;
delete p;
return true;
}
typedef struct StackNode {
int data;
struct StackNode *next;
}StackNode,*LiStack;
//带头结点
//初始化
void InitStack(LiStack &S) {
S->next = NULL;
}
//入栈
void Push(LiStack &S,int x) {
StackNode *p = new StackNode;
p->data = x;
p->next = S->next;
S->next = p;
}
//出栈
bool Push(LiStack &S,int &x) {
if(S->next==NULL)
return false;
x = S->next->data;
StackNode *p = S->next;
S->next = p->next;
free(p);
return true;
}