赞
踩
- #include <stdio.h>
- #include <stdlib.h>
-
- #define T 1
- #define F 0
-
- typedef int Status;
- typedef int ElemType;
-
- typedef struct StackNode//链式存储的结点
- {
- ElemType data;//数据域
- struct StackNode* next;//指针域
- }StackNode, *LinkStackPtr;
-
- typedef struct LinkStack//栈
- {
- LinkStackPtr top;//top即栈顶 放在单链表的头部,对于链栈来说不需要头结点
- int count;//栈的长度
- }LinkStack;
-
- void init(LinkStack* S);
- Status push(LinkStack* S, ElemType e);
- Status pop(LinkStack* S, ElemType* e);
- Status stackEmpty(LinkStack S);
-
- int main()
- {
- int i = 0, num = 0;
- LinkStack S;
- init(&S);
- for (; i < 10; i++)
- {
- push(&S, i);
- }
- for (; i > 0; i--)
- {
- pop(&S, &num);
- printf("%d\n", num);
- }
- return 0;
- }
-
- void init(LinkStack* S)//初始化为空栈
- {
- S->top = NULL;
- S->count = 0;
- }
-
- Status push(LinkStack* S, ElemType e)
- {
- //和链表一样正常创建结点
- LinkStackPtr s = (LinkStackPtr)malloc(sizeof(StackNode));
- s->data = e;
- s->next = S->top;//往
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。