00001
00029 #ifndef ABA_LIST_INC
00030 #define ABA_LIST_INC
00031
00032 template<class Type>
00033 inline ABA_LIST<Type>::ABA_LIST(const ABA_GLOBAL *glob)
00034 :
00035 glob_(glob),
00036 first_(0),
00037 last_(0)
00038 { }
00039
00040 template<class Type>
00041 ABA_LIST<Type>::~ABA_LIST()
00042 {
00043 ABA_LISTITEM<Type> *item = first_;
00044 ABA_LISTITEM<Type> *del;
00045
00046 while (item) {
00047 del = item;
00048 item = item->succ_;
00049 delete del;
00050 }
00051 }
00052
00053 template <class Type>
00054 ostream& operator<<(ostream &out, const ABA_LIST<Type> &list)
00055 {
00056 ABA_LISTITEM<Type> *item = list.first_;
00057
00058 while (item != 0) {
00059 out << *item << " ";
00060 item = item->succ();
00061 }
00062 out << endl;
00063 return out;
00064 }
00065
00066 template<class Type>
00067 inline void ABA_LIST<Type>::appendHead(const Type &elem)
00068 {
00069 appendHead(new ABA_LISTITEM<Type>(elem, first_));
00070 }
00071
00072 template<class Type>
00073 inline void ABA_LIST<Type>::appendHead(ABA_LISTITEM<Type> *item)
00074 {
00075 first_ = item;
00076 if (last_ == 0) last_ = item;
00077 }
00078
00079 template<class Type>
00080 inline void ABA_LIST<Type>::appendTail(const Type &elem)
00081 {
00082 appendTail(new ABA_LISTITEM<Type>(elem, 0));
00083 }
00084
00085 template<class Type>
00086 inline void ABA_LIST<Type>::appendTail(ABA_LISTITEM<Type> *item)
00087 {
00088 if (first_ == 0) first_ = item;
00089 else last_->succ_ = item;
00090 last_ = item;
00091 }
00092
00093 template <class Type>
00094 int ABA_LIST<Type>::extractHead(Type &elem)
00095 {
00096 int status;
00097 if ((status = firstElem(elem))) return status;
00098
00099 ABA_LISTITEM<Type> *second = first_->succ_;
00100
00101 delete first_;
00102 first_ = second;
00103
00104 if (first_ == 0) last_ = 0;
00105
00106 return status;
00107 }
00108
00109 template <class Type>
00110 inline int ABA_LIST<Type>::firstElem(Type &elem) const
00111 {
00112 if (empty()) return 1;
00113 elem = first()->elem();
00114 return 0;
00115 }
00116
00117 template<class Type>
00118 inline ABA_LISTITEM<Type> * ABA_LIST<Type>::first() const
00119 {
00120 return first_;
00121 }
00122
00123 template<class Type>
00124 inline ABA_LISTITEM<Type> * ABA_LIST<Type>::last() const
00125 {
00126 return last_;
00127 }
00128
00129 template<class Type>
00130 inline bool ABA_LIST<Type>::empty() const
00131 {
00132 return first_ == 0 ? true : false;
00133 }
00134
00135 #endif // ABA_LIST_INC