lstack.h
来自「不带括号算术式求值另外一个版本 可以自动判断优先级 排除空格等字符影响」· C头文件 代码 · 共 77 行
H
77 行
#ifndef LLSTACK_H
#define LLSTACK_H
#include "link.h"
#include "stack.h"
template<class Elem>
class LStack :public Stack<Elem>
{
private:
Link<Elem> *top;
public:
LStack()
{
top=NULL;
}
~LStack()
{
clear();
}
bool empty() const;
void clear();
bool push(const Elem &item);
bool pop();
bool topValue(Elem &item) const;
};
template<class Elem>
bool LStack<Elem>::empty() const
{
if(top==NULL)
return 1;
else
return 0;
}
template<class Elem>
void LStack<Elem>::clear()
{
while (!empty())
pop();
}
template<class Elem>
bool LStack<Elem>::push(const Elem &item)
{
Link<Elem> *new_top = new Link<Elem>(item, top);
if (new_top == NULL) return 0;
top = new_top;
return 1;
}
template<class Elem>
bool LStack<Elem>::pop()
{
Link<Elem> *old_top = top;
if (top == NULL) return 0;
top = old_top->next;
delete old_top;
return 1;
}
template<class Elem>
bool LStack<Elem>::topValue(Elem &item) const
{
if(empty())
return 0;
else{
item=top->element;
return 1;
}
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?