template <typename T>
struct list_element {
list_element<T> * next;
T value;
}
template <typename T>
struct list {
list_element<T> * begin, end;
}
push_front() and pop_front() are fast and reasonably
simple
le = new list_element; // this code is incomplete. (why?) le->next = lhead.begin; lhead.begin = le;
le = lhead.begin; // this code is incomplete. (why?) lhead.begin = le->next; delete le;
push_back() and pop_back() are reasonably simple and ...
push_back() and pop_back() slow
template <typename T>
struct list_element {
list_element<T> * previous, next;
T value;
}
push_back() and pop_back() are fast if a bit less
simple to do.
le = new list_element // this code is incomplete. (why?) le->previous = lhead.end le->next = nil lhead.end->next = le lhead.end = le
le = lhead.end // this code is incomplete. (why?) le->previous->next = nil lhead.end = le->previous delete le
insert() and erase() are also fast and simple with
doubly-linked lists
splice() is also fast and simple to do with doubly-linked
lists
template <typedef T, int size>
struct list {
vector<int> previous(size), next(size);
vector<T> values(size);
int begin, end;
int free;
}
i-th list element
list.values[i] is its value
list.previous[i] is the index of the previous list element
list.next[i] is the index of the next list element
list.begin and list.end are the indices of the first and
last elements on the list.
This page last modified on 25 July 2000.