#include#include typedef struct node { int num; struct node* next; }node; typedef struct linkstack { struct node*top; int count; }linkstack; void init(linkstack* s)//初始化 { s->count = 0; s->top = NULL; } void push(linkstack* s,int new)//压栈 { node* p = NULL; p= (node*)malloc(sizeof(node)); p->num = new; p->next =s->top; s->top = p; } void print(linkstack* s)//打印数据 { printf("*存储的数据:n"); int n = 1; printf("n"); while (s->top!= NULL) { if(n==1){ printf(" top->| %d |n", s->top->num); } else { printf(" | %d |n", s->top->num); } s->top = s->top->next; n++; } } int pop(linkstack* s)//出栈 { int a = s->top->num; s->top = s->top->next; return a; } int gettop(linkstack* s)//返回栈顶元素 { return s->top->num; } int main() { linkstack stack; init(&stack); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)