Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #ifndef LHEAPSET_H 00010 #define LHEAPSET_H 00011 00012 #include "Adt.h" 00013 #include "Util.h" 00014 #include "List.h" 00015 00016 namespace grafalgo { 00017 00018 typedef int keytyp; 00019 typedef int lheap; 00020 00026 class LheapSet : public Adt { 00027 public: LheapSet(int=100); 00028 ~LheapSet(); 00029 00030 // common methods 00031 void clear(); 00032 void resize(int); 00033 void expand(int); 00034 void copyFrom(const LheapSet&); 00035 00036 keytyp key(index) const; 00037 void setkey(index,keytyp); 00038 00039 lheap findmin(lheap) const; 00040 lheap meld(lheap,lheap); 00041 lheap insert(index,lheap); 00042 index deletemin(lheap); 00043 00044 string& toString(string&) const; 00045 string& heap2string(lheap, string&) const; 00046 protected: 00047 struct hnode { 00048 keytyp kee; 00049 int rank; 00050 int left; 00051 int right; 00052 } *node; 00053 00054 string& heap2string(lheap, bool, string&) const; 00055 void makeSpace(int); 00056 void freeSpace(); 00057 }; 00058 00063 inline keytyp LheapSet::key(index i) const { return node[i].kee; }; 00064 00069 inline void LheapSet::setkey(index i,keytyp k) { node[i].kee = k; }; 00070 00075 inline lheap LheapSet::findmin(lheap h) const { return h; }; 00076 00082 inline string& LheapSet::heap2string(lheap h, string& s) const { 00083 return heap2string(h,true,s); 00084 } 00085 00086 } // ends namespace 00087 00088 #endif