lstack1.h

来自「问题描述: 假设一个商店」· C头文件 代码 · 共 73 行

H
73
字号
#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 + =
减小字号Ctrl + -
显示快捷键?