lstack.h
来自「该压缩文件夹内有诸多常用算法和数据结构的c++模板编程实现」· C头文件 代码 · 共 73 行
H
73 行
#ifndef LSTACK
#define LSTACK
#include<iostream.h>
#include"node.h"
template <class T>
class lStack
{
private:
node<T> *head,*tail;
public:
lStack() {head=tail=NULL;}
bool isEmpty()
{
if(head==NULL)
return true;
else
return false;
}
T topEl()
{
T el=tail->info;
return el;
}
T pop()
{
T el=tail->info;
if(head==tail)
{
tail=NULL;
delete head;
head=NULL;
}
else
{
for(node<T> *p=head;p->next!=tail;p=p->next);
p->next=NULL;
delete tail;
tail=p;
}
return el;
}
void push(T el)
{
if(head==NULL)
head=tail=new node<T>(el);
else
{
tail->next=new node<T>(el);
tail=tail->next;
}
}
void clear()
{
node<T> *p=head;
while(head!=NULL)
{
p=head;
head=head->next;
delete p;
}
tail=NULL;
}
int size()
{
int i=0;
for(node<T> *p=head;p!=NULL;p=p->next)
i++;
return i;
}
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?