c实现链栈基 ***

c实现链栈基 *** ,第1张

c实现链栈基 ***
#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;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5702920.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存