#include <stdio.h>
#include <stdlib.h>
struct stack //定义结构体
{
int data;
struct stack *next;
};
void Init(struct stack **p) //初始化头指针
{
*p = NULL;
}
struct stack *Creat(int x) //创建新节点
{
struct stack *t;
t=(struct stack *)malloc(sizeof(struct stack));
t->data = x;
t->next = NULL;
};
void Push(struct stack **p, int x) //进栈
{
struct stack *t;
t = Creat(x);
t->next = *p;
*p = t;
}
int Pop(struct stack **p, int *px) //弹栈
{
if(*p){
struct stack *t;
t = *p;
*px = (*p)->data;
*p = t->next;
free(t);
return 1;
}
else
return 0;
}
链式栈的实现
最新推荐文章于 2022-08-17 20:07:25 发布