链栈的定义
#include <iostream>
using namespace std;
typedef struct _QNode
{
int data;
struct _QNode *next;
}StNode;
链栈的操作
初始化
bool initStack(StNode* &st)
{
st = new StNode;
if(!st) return false;
st->next = NULL;
return true;
}
判断栈空
bool isEmpty(StNode *st)
{
if(st->next == NULL)
return true;
else
return false;
}
入栈
bool pushStack(StNode* &st, int e)
{
StNode *node = new StNode;
if(!node) return false;
node->data = e;
node->next = st->next;
st->next = node;
return true;
}
出栈
bool popStack(StNode* &st, int &e)
{
if(!(st->next)) return false;
StNode *p;
p = st->next;
e = p->data;
st->next = p->next;
delete p;
return true;
}