#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#define MAX 100
struct node{
int data;
struct *next;
}s;
//初始化
int InitStack(&s){
s=(node *)malloc(sizeof(node));
if(NULL==s)
return -1;
s->next=NULL;
}
//判空
int StackEmpty(&s){
if(NULL==s->next)
return 1;
return 0;
}
//求长度
int StackLength(&s){
int count=0;
node *p=s;
while(NULL!=p->next){
p=p->next;
count++;
}
return count;
}
//访问栈顶
int GetTop(&s,int *e){
if(StackEmpty(*s))
return -1;
*e=s->next->data;
return 0;
}
//入栈
int Push(&s,int e){
node *p;
p=(node *)malloc(sizeof(node));
if(p==NULL)
return -1;
p->data=e;
p->next=s->next;
s->next=p;
return 0;
}
//出栈
int Pop(&s,int *e){
node *p=NULL;
if(StackEmpty(*s))
return -1;
p=s->next;
*e=p->data;
s->next=p->next;
free(p);
return 0;
}
//主函数
int main(){
}
转载于:https://www.cnblogs.com/100114jerro/p/4998735.html