C语言顺序栈

栈为只能在一端修改数据的数据结构,顺序栈结构为一个数组和一个指向尾部的top变量,当进栈时把元素放入下标为top的数组元素中去,top+1。出栈的话就是top-1

 1 #include<stdio.h>
 2 #define MAXSIZE 1024
 3 
 4 typedef int elemtype;
 5 
 6 typedef struct sequenStack{
 7     elemtype date[MAXSIZE];
 8     int top;
 9 }SequenStack;
10 
11 int Pop_SequenStack(SequenStack *p,elemtype *e){//出栈
12     
13     if(p->top<0)
14         return 0;
15     
16     *e = p->date[p->top];
17     p->top--;
18     return 1;
19     
20 }
21 
22 int Push_SequenStack(SequenStack *p,elemtype e){//入栈
23     
24     if(p->top>=MAXSIZE-1)
25         return 0;
26     
27     p->top++;
28     p->date[p->top] = e;
29     return 1;
30     
31 }
32 
33 SequenStack *init_SequenStack(){//初始化
34     
35     SequenStack *p = (SequenStack *)malloc(sizeof(SequenStack));
36     if(p==NULL)
37         return NULL;
38     
39     p->top = -1;
40     return p;
41     
42 }
43 
44 void main(){
45     
46     SequenStack *top = init_SequenStack();
47     
48 }

 

posted @ 2018-11-27 17:09  捞的不谈  阅读(468)  评论(0编辑  收藏  举报