1 #define MAXSIZE 100
 2 
 3 struct doublestack
 4 {
 5     int number[MAXSIZE];
 6     int top1=-1;
 7     int top2=MAXSIZE;
 8 };
 9 
10 
11 void Push(doublestack *s, int e, int n)
12 {
13     //栈满
14     if (s->top1 + 1 == s->top2)
15         exit(1);
16     if (n == 1)
17     {
18         s->top1++;
19         s->number[s->top1]=e;
20     }
21     else if (n == 2)
22     {
23         s->top2--;
24         s->number[s->top2] = e;
25     }
26 }
27 
28 
29 int Pop(doublestack *s, int n)
30 {
31     int t;
32     if (n == 1)
33     {
34         if (s->top1 == -1)
35             return -1;
36         t = s->number[s->top1--];
37     }
38     else if (n == 2)
39     {
40         if (s->top2 == MAXSIZE)
41             return -1;
42         t = s->number[s->top2++];
43     }
44     return t;
45 }

 

posted on 2017-02-24 13:03  郑哲  阅读(138)  评论(0编辑  收藏  举报