1.链栈的表示:
typedef struct LinkNode{
ElemType data;
LinkNode *next;
}LinkNode,*LinkStack;
2.链栈的初始化:
void InitLinkStack(LinkStack &S){
S = (LinkNode*)malloc(sizeof(LinkNode));
S->next = NULL;
}
3.判断链栈是否为空:
bool LinkStackEmpty(LinkStack S){
if(S->next == NULL) return true;
return false;
}
4.进栈:
void Push(LinkStack &S, ElemType e){
LinkNode* p;
p = (LinkNode*)malloc(sizeof(LinkNode));
p->next = NULL;
p->data = e;
S->next = p;
S = s->next;
}
5.出栈:
int Pop(LinkStack &S, ElemType &e){
if(S->next == NULL) return ERROR;
e = S->data;
S = S->next;
}
6.销毁链栈:
//以后再来写
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)