21 template <
typename TYPE>
22 tlp::BmdList<TYPE>::BmdList() : head(nullptr), tail(nullptr), count(0) {}
24 template <
typename TYPE>
25 tlp::BmdList<TYPE>::~BmdList() {
29 template <
typename TYPE>
30 tlp::BmdLink<TYPE> *tlp::BmdList<TYPE>::firstItem() {
34 template <
typename TYPE>
35 tlp::BmdLink<TYPE> *tlp::BmdList<TYPE>::lastItem() {
39 template <
typename TYPE>
40 TYPE tlp::BmdList<TYPE>::entry(tlp::BmdLink<TYPE> *it) {
44 template <
typename TYPE>
45 int BmdList<TYPE>::size() {
49 template <
typename TYPE>
50 tlp::BmdLink<TYPE> *BmdList<TYPE>::nextItem(tlp::BmdLink<TYPE> *p, tlp::BmdLink<TYPE> *predP) {
58 if (p->prev() != predP)
66 template <
typename TYPE>
67 tlp::BmdLink<TYPE> *tlp::BmdList<TYPE>::predItem(tlp::BmdLink<TYPE> *p, tlp::BmdLink<TYPE> *succP) {
75 if (p->succ() != succP)
83 template <
typename TYPE>
84 tlp::BmdLink<TYPE> *tlp::BmdList<TYPE>::cyclicPred(tlp::BmdLink<TYPE> *it,
85 tlp::BmdLink<TYPE> *succIt) {
95 return predItem(it, succIt);
98 template <
typename TYPE>
99 tlp::BmdLink<TYPE> *tlp::BmdList<TYPE>::cyclicSucc(tlp::BmdLink<TYPE> *it,
100 tlp::BmdLink<TYPE> *predIt) {
110 return nextItem(it, predIt);
113 template <
typename TYPE>
114 tlp::BmdLink<TYPE> *tlp::BmdList<TYPE>::push(
const TYPE &data) {
117 if (head !=
nullptr) {
118 if (head->suc !=
nullptr)
119 head = head->pre =
new tlp::BmdLink<TYPE>(data,
nullptr, head);
121 head = head->suc =
new tlp::BmdLink<TYPE>(data,
nullptr, head);
123 head = tail =
new tlp::BmdLink<TYPE>(data,
nullptr,
nullptr);
128 template <
typename TYPE>
129 tlp::BmdLink<TYPE> *tlp::BmdList<TYPE>::append(
const TYPE &data) {
132 if (tail !=
nullptr) {
133 if (tail->pre !=
nullptr)
134 tail = tail->suc =
new tlp::BmdLink<TYPE>(data, tail,
nullptr);
136 tail = tail->pre =
new tlp::BmdLink<TYPE>(data, tail,
nullptr);
139 tail = head =
new tlp::BmdLink<TYPE>(data,
nullptr,
nullptr);
145 template <
typename TYPE>
146 TYPE tlp::BmdList<TYPE>::delItem(tlp::BmdLink<TYPE> *it) {
147 assert(it !=
nullptr);
155 tlp::BmdLink<TYPE> *p = predItem(it,
nullptr);
156 tlp::BmdLink<TYPE> *s = nextItem(it, p);
174 template <
typename TYPE>
175 TYPE tlp::BmdList<TYPE>::pop() {
176 assert(head !=
nullptr);
177 tlp::BmdLink<TYPE> *x = head;
178 head = nextItem(head,
nullptr);
194 template <
typename TYPE>
195 TYPE tlp::BmdList<TYPE>::popBack() {
196 assert(head !=
nullptr);
197 tlp::BmdLink<TYPE> *x = tail;
198 tail = predItem(tail,
nullptr);
214 template <
typename TYPE>
215 void tlp::BmdList<TYPE>::reverse() {
216 tlp::BmdLink<TYPE> *x = head;
221 template <
typename TYPE>
222 void tlp::BmdList<TYPE>::conc(tlp::BmdList<TYPE> &l) {
223 if (head ==
nullptr) {
227 if (tail->pre ==
nullptr)
233 if (l.head->suc ==
nullptr)
243 l.head = l.tail =
nullptr;
247 template <
typename TYPE>
248 void tlp::BmdList<TYPE>::clear() {
252 tlp::BmdLink<TYPE> *it = head;
253 tlp::BmdLink<TYPE> *p = head;
255 for (
int i = 0; i < count; i++) {
256 tlp::BmdLink<TYPE> *x = it;
257 it = nextItem(it, p);
267 head = tail =
nullptr;
270 template <
typename TYPE>
271 void tlp::BmdList<TYPE>::swap(tlp::BmdList<TYPE> &l) {
272 tlp::BmdLink<TYPE> *tmp;