⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lstack1.h

📁 构造接受语言{{}}的一台自动机
💻 H
字号:
#ifndef LSTACK1_H
#define LSTACK1_H
#include "link3.h"
template<class Elem>class LStack1
{
  private:
    Link<Elem>* top;
    int size;
  public:
    LStack1(){top=NULL;size=0;}
    ~LStack1(){clear();}
    void clear()
    {
      while(top!=NULL)
      {
        Link<Elem>* temp=top;
        top=top->next;
        size=0;
        delete temp;
      }
    }
    bool push(const Elem& item)
    {
       top=new Link<Elem>(item,top);
       size++;
       return true;
    }
    bool pop(Elem& it)
    {
      if(size==0)return false;
      it=top->element;
      Link<Elem>* ltemp=top->next;
      delete top;
      top=ltemp;
      size--;
      return true;
    }
    bool topValue(Elem& it)const
    {
      if(size==0)return false;
      it=top->element;
      return true;
    }
    bool play()
    {  int tempsize=size;
       Link<Elem>* temptop=top;
       while(tempsize!=0)
       {   tempsize--;
           cout<<temptop->element;
           temptop=temptop->next;
       }
       return false;
    }
    int length()const {return size;}
};
#endif
















⌨️ 快捷键说明

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