优美的低于生活
李某人
全部博文(81)
存储备份 集群(0)
桌面应用(1)
iptables squid(2)
kernel shell(4)
服务器应用(17)
系统管理(23)
2011年(1)
2009年(22)
2008年(58)
yshisx
_nosay
fjzhuozl
ls549756
ncesun
lonergd
11194012
davoqiu
cainiao_
分类: C/C++
2009-06-01 10:38:02
#include <stdio.h>typedef char Element;typedef struct Node { Element data; struct Node *next; } StackNode;typedef struct { StackNode *top;} LinkStack;void initstack(LinkStack *ls){ ls->top = NULL;}int isempty(LinkStack *ls){ return ls->top == NULL;}void push(LinkStack *ls, Element el) { StackNode *p; p = (StackNode *)malloc( sizeof(StackNode) ); p->data = el; p->next = ls->top; ls->top = p;}Element pop(LinkStack *ls){ StackNode *p = ls->top; Element popdata = ls->top->data; ls->top = ls->top->next; free(p); return popdata;}void traverse(LinkStack *ls){ int i = 0; StackNode *node = ls->top; while(node->next != NULL) { node = node->next; printf("LinkStack Node %d is %c\n", i, node->data); i++; }}int main(){ LinkStack *ls; char indata; ls = (LinkStack *)malloc( sizeof(LinkStack) ); printf("Please input data\n"); while(indata != '\n') { scanf("%c", &indata); push(ls, indata); printf("push %c to stack\n", indata); } printf("print linkStack:\n"); traverse(ls); printf("pop stack\n"); pop(ls); traverse(ls); printf("pop stack\n"); pop(ls); traverse(ls); }
上一篇:sigsetjmp和siglongjmp
下一篇:struct 与 typedef
登录 注册