[作业]链式栈的进栈和出栈

[作业]链式栈的进栈和出栈

去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

// 
#include "stdio.h"
#include "malloc.h"

typedef struct LNode {
	int  data;
	struct LNode *next;
}LNode, LStack;

void Lpush(LNode *&s, int e)
{
	LNode *p;
	p = (LNode*)malloc(sizeof(LNode));
	p->data = e;
	p->next = s;
	s = p;
} //Lpush

LNode* InitLStack() {
	LNode* s;
	int n;
	s = (LNode*)malloc(sizeof(LNode));
	s->data = 9527;
	s->next = NULL;

	for (int i = 1; i <10; i++)
	{
		Lpush(s, i * 100 + i * 10 + i);
	}
	return s;
} //InitLStack



int Lpop(LNode *&s) {
	if (s) {
		int d = s->data;
		s = s->next;
		return d;
	}
	else {
		return 0;
	}
} //Lpop

int main() {
	LNode* S1;
	S1 = InitLStack();
	while (S1)
	{
		printf("%d\n", Lpop(S1));
	}
}

你可能感兴趣的:([作业]链式栈的进栈和出栈)