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

📄 linkedlistwithtail.h

📁 用于词法分析的词法分析器
💻 H
字号:
/*  $Id: LinkedListWithTail.h,v 1.6 1997/04/02 12:38:12 matt Exp $  Linked list with tail: allows items to be added to the end of the  list as well as the head.    (c) Mar 95 Matt Phillips.  NOTE: use LinkedListWithTailIterExt for extended iterator.  */#ifndef _LLISTT_H#define _LLISTT_H#include "LinkedList.h"template <class T, class E>class LinkedListWithTailImp : public LinkedListImp<T, E>{public:  typedef LinkedListWithTailImpIter<T, E> Iterator;  LinkedListWithTailImp () : tail (0) {}  LinkedListWithTailImp (const LinkedListWithTailImp<T, E> &l) : tail (0)  {    addTail (l);  }  // Adds <i> to the head of the list.  void add (T &i)  {LinkedListImp<T, E>::add (i); if (tail == 0) tail = head;}  // Adds <i> to end of the list.  void addTail (T &i);  // Appends copy of <list> to the end of this list.  void addTail (const LinkedListWithTailImp<T, E> &list);  // Returns the element at the end of the list.  T &peekTail () const  {    CHECK (tail, "peek on empty list");    return tail->ref ();  }  // Moves all elements in the list to <dest> (list is cleared).  void moveTo (LinkedListWithTailImp<T, E> &dest);  Iterator *makeIter () const {return new Iterator (*this);}protected:  friend class Iterator;  E *tail;};template <class T, class E>void LinkedListWithTailImp<T, E>::addTail (const LinkedListWithTailImp<T, E> &list){  E *newItem = 0;  for (E *src = list.head, *prev = tail; src;       src = src->next, prev = newItem)  {    newItem = new E (src->ref ());    newItem->copy (src->ref ());    if (prev)      prev->next = newItem;    else      head = newItem;  }  tail = newItem;  _nItems += list._nItems;}template <class T, class E>class LinkedListWithTailImpIter : public LinkedListImpIter<T, E>{public:  LinkedListWithTailImpIter (const LinkedListWithTailImp<T, E> &l) :    LinkedListImpIter<T, E> (l) {}protected:  // hack to allow extended iterators access to tail  void setTail (E *t) {((LinkedListWithTailImp<T, E> &)list).tail = t;}};template <class T, class E>void LinkedListWithTailImp<T, E>::addTail (T &i){  E *e = new E (i);    e->next = 0;     if (tail)  {    tail->next = e;    tail = e;  } else    head = tail = e;     _nItems++;}template <class T, class E>void LinkedListWithTailImp<T, E>::moveTo (LinkedListWithTailImp<T, E> &dest){  if (this == &dest || _nItems == 0)    return;			// return immediately if dest = src  if (dest.tail)    dest.tail->next = head;  else    dest.head = head;  dest.tail = tail;  dest._nItems += _nItems;  _nItems = 0;  head = tail = 0;}#define TypeDLinkedListWithTail(T)  LinkedListWithTailImp<T, DLinkedItem<T> >#define TypeIOLinkedListWithTail(T) LinkedListWithTailImp<T, ILinkedItem<T, 1> >#define TypeILinkedListWithTail(T)  LinkedListWithTailImp<T, ILinkedItem<T, 0> >#endif

⌨️ 快捷键说明

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