zoukankan      html  css  js  c++  java
  • 两栈共享空间

     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 }

  • 相关阅读:
    cookie操作
    css加载动画...
    三目运算符的运用
    遍历对象长度
    2年
    相亲

    股市周期
    功利心
    思考笔记
  • 原文地址:https://www.cnblogs.com/zhengzhe/p/6438117.html
Copyright © 2011-2022 走看看