typedef int DataType;
struct node{
DataType info;
bool flag;//true->symbol false->num
struct node *link;
};
typedef struct node *PNode;
struct LinkStack{
PNode top;
};
typedef struct LinkStack *PLinkStack;
PLinkStack createNullStack_link(){
PLinkStack s = new struct LinkStack;
s->top = NULL;
return s;
}
int isNullStack_link(PLinkStack L){
if(L == NULL)return -1;
if(L->top == NULL)return 1;
return 0;
}
int isEmpty_link(PLinkStack s){
return s->top == NULL;
}
int push_link(PLinkStack L,DataType x,bool flag){
PNode node = new struct node;
if(!node)return 0;
node->info = x;
node->flag = flag;
node->link = L->top;
L->top = node;
return 1;
}
PNode pop_link(PLinkStack L){
if(L == NULL)return NULL;
if(L->top == NULL)return NULL;
PNode node = L->top;
L->top = L->top->link;
return node;
}
PNode top_link(PLinkStack L){
return L->top;
}
链栈代码
最新推荐文章于 2024-09-06 10:38:06 发布