栈(链式存储)
typedef struct SNode *PtrToSNode;
struct SNode{
ElemType data;
PtrToSNode next;
};
typedef PtrToSNode Stack;
stack CreateStack(){
Stack s;
s=(Stcak)malloc(sizeof(struct SNode));
s->next=NULL;
return s;
}
bool isEmpty(){
return s->next==null;
}
bool push(Stack s,ElemType e){
PtrToSNode temp;
temp=(PtrToSNode)malloc(sizeof(struct SNode));
temp->data=e;
temp->next=s->next;
s->next=temp;
return ture;
}
ElemType pop(Stack s){
PtrToSNode first;
ElemType topElem;
if(isEmpty()){
print("栈空");
return ERROR;
}
else {
first=s->next;
topElem=first->data;
s->next=first->next;
free(first);
return topElem;
}
}