📄 task2.h
字号:
const int maxstack = 10;
#define Stack_H
#ifndef Stack_H
//#include <stack>
typedef char Stack_entry;
enum Error_code
{
success,overflow,underflow
};
class Stack
{
public:
Stack();
Error_code pop();
Error_code push(const Stack_entry &item);
Error_code top(Stack_entry &item) const;
bool empty() const;
void clear(); // Reset the stack to be empty.
bool full() const; // If the stack is full, return true; else return false.
int size() const; // Return the number of entries in the stack.
private:
int count;
Stack_entry entry[maxstack];
};
Stack::Stack()
{
count=0;
}
Error_code Stack::pop()
{
Error_code outcome = success;
if (count == 0)
outcome = underflow;
else --count;
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;
}
Error_code Stack::top(Stack_entry &item) const
{
Error_code outcome = success;
if (count == 0)
outcome = underflow;
else
item = entry[count - 1];
return outcome;
}
bool Stack::empty() const
{
bool outcome = true;
if (count > 0) outcome = false;
return outcome;
}
void Stack::clear()//清空栈内元素
{
count=0;
}
bool Stack::full() const //判断栈是否是满的
{
/*if(count >= maxstack)
return (false);
else
return (true);*/
count >= maxstack;
}
int Stack::size() const//计算栈内元素的个数
{
return count;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -