// -*- Mode: C++ -*- // GiSTlist.h // // Copyright (c) 1996, Regents of the University of California // $Header: /schmorpforge/Tree-M/GiST/GiSTlist.h,v 1.1 2001/05/06 00:45:52 root Exp $ #ifndef GISTLIST_H #define GISTLIST_H // A template list package, which is handy. template struct GiSTlistnode { T entry; GiSTlistnode *prev, *next; }; template class GiSTlist { public: GiSTlist() { front=rear=NULL; } // GiSTlist(const GiSTlist& l) { front=l.front; rear=l.rear; } int IsEmpty() { return front==NULL; } T RemoveFront() { assert(front!=NULL); GiSTlistnode *temp=front; T e=front->entry; front=front->next; if(front) front->prev=NULL; else rear=NULL; delete temp; return e; } T RemoveRear() { assert(rear!=NULL); GiSTlistnode *temp=rear; T e=rear->entry; rear=rear->prev; if(rear) rear->next=NULL; else front=NULL; delete temp; return e; } void Prepend(T entry) { GiSTlistnode *temp=new GiSTlistnode; temp->entry=entry; temp->next=front; temp->prev=NULL; if(rear==NULL) rear=temp; else front->prev=temp; front=temp; } void Append(T entry) { GiSTlistnode *temp=new GiSTlistnode; temp->entry=entry; temp->prev=rear; temp->next=NULL; if(front==NULL) front=temp; else rear->next=temp; rear=temp; } //private: GiSTlistnode *front, *rear; }; #endif