llstack.h
来自「迷宫问题」· C头文件 代码 · 共 59 行
H
59 行
//generic stack defined as a linked list
#ifndef LL_STACK
#define LL_STACK
#include "tlist.h"
//using namespace std;
template<class T>
class LLStack
{
public:
LLStack();
~LLStack();
bool empty();
T top();
T pop();
void push(const T& el);
private:
TLIST<T> list;
};
template<class T>
LLStack<T>::LLStack()
{}
template<class T>
LLStack<T>::~LLStack()
{
T next;
while(!empty())
next=pop();
}
template<class T>
bool LLStack<T>::empty()
{
return (list.isempty());
}
template<class T>
T LLStack<T>::top()
{
return list.getLast();
}
template<class T>
T LLStack<T>::pop()
{
T el=list.getLast();
list.pop_back();
return el;
}
template<class T>
void LLStack<T>::push(const T& el)
{
list.push_back(el);
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?