// -*-c++-*- #ifndef LIST_INL #define LIST_INL template inline List::List() { set_empty(); } template inline void List::set_empty() { top_ = bottom_ = 0; size_ = 0; } template inline List::List( const T& thing ) { set_empty(); add( thing, Cursor( *this, bottom_ ) ); } template inline List::~List() { Cursor next(*this); for ( Cursor c( *this ); c.ok(); c = next ) { next = c; next++; remove( c ); } } template inline void List::add( const T& thing, Cursor after_me ) { #if 0 if ( after_me.ok() ) after_me.pointer()->add( thing ); else if ( size_ ) bottom().pointer()->add( thing ); else bottom_ = top_ = new Link( thing ); #endif if (!size_) { // not much choice if list is empty bottom_ = top_ = new Link( thing ); } else { // add at aprioprate place Link *p = ( after_me.ok() ) ? after_me.pointer() : bottom().pointer(); p->add(thing); if (p == bottom_) // adjust bottom_ if necessary. bottom_ = p->next(); } size_++; } /** Procedure: \begin{itemize} \item if #after_me# is #ok()#, add after #after_me#, else \item if list !empty simply add to bottom, else \item list is empty: create first \Ref{Link} and initialize #bottom_# and #top_#. \end{itemize} */ template inline void List::insert( const T& thing, Cursor before_me ) { if (!size_) { bottom_ = top_ = new Link( thing ); } else { Link *p = (before_me.ok())? before_me.pointer() : top().pointer(); p->insert(thing); if (p == top_) top_ = p->previous(); } size_++; #if 0 // rewrite hwn 16/9 if ( before_me.ok() ) before_me.pointer()->insert( thing ); else if ( size_ ) top().pointer()->insert( thing ); else bottom_ = top_ = new Link( thing ); size_++; #endif } template inline void List::remove( Cursor me ) { if ( me.ok() ){ Link *lp = me.pointer(); lp->remove(*this); delete lp; size_--; } } template inline int List::size() const { return size_; } #endif