Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/include/Dlist.h
Go to the documentation of this file.
00001 
00009 #ifndef DLIST_H
00010 #define DLIST_H
00011 
00012 #include "stdinc.h"
00013 #include "List.h"
00014 
00015 namespace grafalgo {
00016 
00025 class Dlist : public List {
00026 public:         Dlist(int=26);
00027                 ~Dlist();
00028 
00029         void    resize(int);
00030         void    expand(int);
00031 
00032         using   List::copyFrom;
00033 
00034         // index access
00035         index   get(index) const;
00036         int     prev(index) const;
00037 
00038         // modifiers
00039         bool    insert(index,index);
00040         bool    remove(index);
00041         bool    removeNext(index);
00042         bool    removeLast();
00043 
00044 protected:
00045         // handle dynamic storage
00046         void    makeSpace(int);   
00047         void    freeSpace();
00048 private:
00049         index   *prv;                   // prv[i] is previous index in list
00050 };
00051 
00056 inline index Dlist::prev(index i) const {
00057         assert(valid(i) && member(i)); return prv[i];
00058 }
00059 
00065 inline bool Dlist::removeNext(index i) {
00066         return remove(i == 0 ? first() : next(i));
00067 }
00068 
00072 inline bool Dlist::removeLast() {
00073         return remove(last());
00074 }
00075 
00076 } // ends namespace
00077 
00078 #endif
 All Classes Files Functions Variables Typedefs Friends