第三十一次发博不知道用什么标题好

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 typedef struct node{
 5     int data;
 6     struct node *next;
 7 }LinkStack; 
 8 
 9 void InitStack(LinkStack *ls)            //初始化栈 
10 {
11     ls=NULL;
12 }
13 
14 void DestroyStack(SqStack *ls)            //销毁栈 
15 {
16     LinkStack *pre=ls,*p;
17     if(pre==NULL)
18     return 0;
19     while(p!=NULL)
20     {
21         free(pre);
22         pre=p;
23         p=p->next;
24     }
25         free(pre);
26 }
27 
28 void Push(LinkStack *ls,ElemType x)        //进栈 
29 {
30     LinkStack *p;
31     p=(LinkStack*)malloc(sizeof(LinkStack));
32     p->data=x;
33     p->next=ls;
34     ls=p;
35 }
36 
37 int Pop(SqStack *st,ElemType *x)        //出栈 
38 {
39     if(st.top==-1)
40     return 0;
41     else
42     {
43         *x=st.data[st.top];
44         st.top--;
45         return 1;
46     }
47     
48 }
49 
50 int GetTop(SqStack st,ElemType *x)        //取出栈顶元素 
51 {
52     if(st.top==-1)
53     return 0;
54     else
55     {
56         *x=st.data[st.top];
57         return 1;
58         
59      } 
60 }
61 
62 intstackEmpty(SqStack st)                //判断栈空 
63 {
64     if(st.top==-1)
65     return 1;
66     else
67     return 0;
68  } 

想起高中班主任当时激励我们的话“死去活来”,嗯越来越觉得学习真的就是这么个过程。

猜你喜欢

转载自www.cnblogs.com/shi-yuan/p/10867155.html