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

📄 lqueue.h

📁 用c实现的二叉树的中序遍历的读取与存储
💻 H
字号:
#ifndef LQUEUE_H
#define LQUEUE_H
#include"link5.h"
#include"binnodeptr1.h"
template <class Elem>class LQueue
{
  private:
    Link<Elem>* front;
    Link<Elem>* rear;
    int size;
  public:
    LQueue()
    {front=NULL;rear=NULL;size=0;}
    ~LQueue()
    {clear();}
    
    void clear()
    {
       while(front!=NULL)
       {
         rear=front;
         front=front->next;
         delete rear;
       }
       rear=NULL;
       size=0;
    }
    bool enqueue(const Elem& it)
    {
      if(rear==NULL)
        front=rear=new Link<Elem>(it,NULL);
      else
        {  rear->next=new Link<Elem>(it,NULL);
           rear=rear->next;
        }
      size++;
      return true;
    }
    bool dequeue(Elem& it)
    {
      if(size==0)return false;
      it=front->element;
      Link<Elem>*ltemp=front;
      front=front->next;
      delete ltemp;
      if(front==NULL)
      rear=NULL;
      size--;
      return true;
    }
    bool frontValue(Elem& it)const
    {
      if(size==0)return false;
      it=front->element;
      return true;
    }
    virtual int length() const {return size;}
};
#endif








⌨️ 快捷键说明

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