From ad1cadf3512f3dd789151983e5c93af411f929db Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sat, 17 Sep 2016 19:27:15 +0000 Subject: restructure --- omegalib/omega_lib/include/basic/SimpleList.c | 105 ++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 omegalib/omega_lib/include/basic/SimpleList.c (limited to 'omegalib/omega_lib/include/basic/SimpleList.c') diff --git a/omegalib/omega_lib/include/basic/SimpleList.c b/omegalib/omega_lib/include/basic/SimpleList.c new file mode 100644 index 0000000..da7de9b --- /dev/null +++ b/omegalib/omega_lib/include/basic/SimpleList.c @@ -0,0 +1,105 @@ +namespace omega { + +template Simple_List_Iterator::Simple_List_Iterator(Simple_List &l) +: List_Element_Iterator(l.contents) {} + +template Simple_List_Iterator::Simple_List_Iterator(const Simple_List &l) +: List_Element_Iterator(l.contents) {} + +template Simple_List_Iterator::Simple_List_Iterator() +: List_Element_Iterator(0) {} + +template Iterator *Simple_List::new_iterator() +{ + return new Simple_List_Iterator(*this); +} + +template const T &Simple_List::operator[](int i) const +{ + Simple_List_Iterator p(*this); + + while(--i > 0 && p) + p++; + + if (p) + return *p; + else + return *((T *)0); +} + +template T &Simple_List::operator[](int i) +{ + Simple_List_Iterator p(*this); + + while(--i > 0 && p) + p++; + + if (p) + return *p; + else + return *((T *)0); +} + + +template int Simple_List::size() const + { + int i = 0; + List_Element * p = contents; + while (p) + { + p = p->tail; + i++; + } + return i; + } + +template T &Simple_List::front() const + { + return contents->head; + } + +template T Simple_List::remove_front() + { + List_Element *frunt = contents; + contents = contents->tail; + T fruntT = frunt->head; + frunt->tail = 0; + delete frunt; + return fruntT; + } + +template void Simple_List::prepend(const T &item) + { + contents = new List_Element(item, contents); + } + + +template void Simple_List::append(const T &item) + { + *(end()) = new List_Element(item, 0); + } + + +template void Simple_List::del_front() + { + List_Element *e = contents; + contents = contents->tail; + e->tail = 0; + delete e; + } + + +template void Simple_List::clear() + { + delete contents; + contents = 0; + } + +template void Simple_List::join(Simple_List &consumed) + { + List_Element *e = consumed.contents; + consumed.contents = 0; + *(end()) = e; + } + +} // namespace -- cgit v1.2.3-70-g09d2