Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #pragma once
00017
00018 #include "maxheap.h"
00019
00020 template <class T> class LinkedEntryT: public MaxHeapOperators {
00021 public:
00022 T data;
00023 void* next;
00024 LinkedEntryT(T& d) { data = d; next = NULL; }
00025 };
00026
00033 template <class T, class TE> class LinkedListT: public MaxHeapOperators
00034 {
00035 private:
00036 TE* head;
00037 TE* tail;
00038 int count;
00039 public:
00042 LinkedListT()
00043 {
00044 head = tail = NULL;
00045 count = 0;
00046 }
00048 ~LinkedListT()
00049 {
00050 New();
00051 }
00054 void New()
00055 {
00056 while(head)
00057 {
00058 TE* next = (TE*)head->next;
00059 delete head;
00060 head = next;
00061 }
00062 head = tail = NULL;
00063 count = 0;
00064 }
00066 int Count() { return count; }
00073 void Append(T& item)
00074 {
00075 TE* entry = new TE(item);
00076 if(tail)
00077 tail->next = entry;
00078 tail = entry;
00079 if(!head)
00080 head = entry;
00081 count++;
00082 }
00088 T& operator[](int index)
00089 {
00090 TE* e = head;
00091 while(index && e) {
00092 e = (TE*)e->next;
00093 index--;
00094 }
00095
00096
00097 if(!e) {
00098 DbgAssert(0);
00099 return head->data;
00100 }
00101 return e->data;
00102 }
00108 LinkedListT& operator=(LinkedListT &from)
00109 {
00110 New();
00111 for(int i = 0; i < from.Count(); ++i)
00112 Append(from[i]);
00113 return *this;
00114 }
00115 };