sortedlinkedlistunique.h

来自「用于词法分析的词法分析器」· C头文件 代码 · 共 61 行

H
61
字号
/*  $Id: SortedLinkedListUnique.h,v 1.2 1997/02/02 01:31:04 matt Exp $  Sorted linked lists with all unique items (no duplicatates).  Requires == and < operators for items.  (c) Oct 1995 Matt Phillips.  */#ifndef _SLLISTU_H#define _SLLISTU_H#include "SortedLinkedList.h"template <class T, class E>class SortedLinkedListUniqueImp : public SortedLinkedListImp<T, E>{public:  SortedLinkedListUniqueImp () {}  SortedLinkedListUniqueImp (const SortedLinkedListUniqueImp<T, E> &l) :    SortedLinkedListImp<T, E> (l) {}  virtual const char *name () const {return "SortedListUnique";}  virtual void add (T &i);};template <class T, class E>void SortedLinkedListUniqueImp<T, E>::add (T &i){  E *prev, *c;  // search list  for (prev = 0, c = head; c && c->ref () < i; prev = c, c = c->next);  // if whole list was searched, or the item after i is not equal to i  if (!c || !(c->ref () == i))  {    if (prev)    {      prev->next = new E (i, prev->next);    } else    {      head = new E (i, head);    }    _nItems++;  } else if (E::isOwner ())  {    delete &i;  }}#define TypeDSortedLinkedListUnique(T)  SortedLinkedListUniqueImp<T, DLinkedItem<T> >#define TypeISortedLinkedListUnique(T)  SortedLinkedListUniqueImp<T, ILinkedItem<T, 0> >#define TypeIOSortedLinkedListUnique(T) SortedLinkedListUniqueImp<T, ILinkedItem<T, 1> >#endif

⌨️ 快捷键说明

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