stack.cpp

来自「包括图、二叉树、链表」· C++ 代码 · 共 52 行

CPP
52
字号
#include "stack.h"
Stack::Stack()
{
   count = 0;
}
bool Stack::empty() const
{
   bool outcome = true;
   if (count > 0) outcome = false;
   return outcome;
}
Error_code Stack::pop()
{
   Error_code outcome = success;
   if (count == 0)
      outcome = underflow;
   else --count;
   return outcome;
}
Error_code Stack::top(Stack_entry &item) const
{
   Error_code outcome = success;
   if (count == 0)
      outcome = underflow;
   else
      item = entry[count - 1];
   return outcome;
}
Error_code Stack::push(const Stack_entry &item)
{
   Error_code outcome = success;
   if (count >= maxstack)
      outcome = overflow;
   else
      entry[count++] = item;
   return outcome;
}
void Stack::clear()
{
	count=0;
}
bool Stack::full() const
{
	return count==maxstack;
}
int Stack::size() const
{
	return count;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?