C++编程之美-结构之法(代码清单3-10)

代码清单3-10

class Queue
{
public:

     Type MaxValue(Type x, Type y)
     {
          if(x > y)
               return x;
          else
               return y;
     }

     Type Queue::Max()
     {
          return MaxValue(stackA.Max(), stackB.Max());
     }

     Insert2Queue(v)
     {
          stackB.push(v);
     }

     Type DeQueue()
     {
          if(stackA.empty())
          {
               while(!stackB.empty())
                    stackA.push(stackB.pop())
          }
          return stackA.pop();
     }

private:

     stack stackA;
     stack stackB;
}
发布了1246 篇原创文章 · 获赞 951 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_42528266/article/details/104028067