46 if (is_head())
return;
47 _cursor = _cursor->get_link(
PREVIOUS);
51 {
return _cursor == to_compare._cursor; }
56 if (*
this == _manager->head()) next();
57 if (*
this == _manager->tail()) previous();
64 if (*
this == _manager->head()) next();
65 if (*
this == _manager->tail()) previous();
71 if (!_manager)
return false;
72 return _cursor == _manager->_head;
77 if (!_manager)
return false;
78 return _cursor == _manager->_tail;
83 if (!_manager)
return;
84 _cursor = _manager->_head;
89 if (!_manager)
return;
90 _cursor = _manager->_tail;
121 if (where._manager !=
this)
return false;
122 if (
empty())
return false;
124 for (
int i = 0; i < new_index; i++) {
126 if (skipper == _tail)
return false;
128 where._cursor = skipper;
134 if (where._manager !=
this)
return false;
135 if (count <= 0)
return true;
138 for (
int i = 0; i < count; i++) where.
next();
144 if (where._manager !=
this)
return false;
145 if (count <= 0)
return true;
148 for (
int i = 0; i < count; i++) where.
previous();
154 if (
empty())
return 0;
157 while (skipper != _tail) {
166 if (where._manager !=
this)
return 0;
170 while ( (where._cursor != skipper) && (skipper != _tail) ) {
179 if (where._manager !=
this)
return 0;
183 while ( (where._cursor != skipper) && (skipper != _head) ) {
206 if (where._cursor == _head)
208 if (where._cursor == _tail)
210 node *old_cursor = where._cursor;
217 where._cursor = old_next;
225 if (where._manager !=
this)
return;
227 if (
empty()) where._cursor = _head;
228 if (where._cursor == _tail)
236 where._cursor = new_node;
241 if (where._manager !=
this)
return;
243 if (
empty()) where._cursor = _tail;
244 if (where._cursor == _head)
252 where._cursor = new_node;
iterators allow the list to be traversed.
void jump_head()
set the iterator to the head.
void jump_tail()
set the iterator to the tail.
void next()
synonym for ++.
void previous()
synonyms for –.
bool is_tail() const
returns true if the cursor is at the tail of the list.
bool is_head() const
returns true if the cursor is at the head of the list.
node * access()
obtain access to the current element.
const node * observe()
peek at the current element.
bool operator==(const iterator &to_compare) const
returns true if the two iterators are at the same position.
void operator--()
go to previous item.
void operator++()
go to next item.
bool backward(iterator &where, int count)
moves the list pointer "count" items towards the head.
bool forward(iterator &where, int count)
moves the list pointer "count" items towards the tail.
int elements() const
returns the number of items currently in the list.
int index(const iterator &it) const
returns the zero-based index of the cursor's position from the head.
bool empty() const
returns true if the list is empty.
~doubly_linked_list()
invalidates all contents of the list and destroys all child nodes.
int items_from_head(const iterator &where) const
Returns the number of elements between the current item and the head.
doubly_linked_list()
constructs a blank list.
iterator head() const
returns an iterator located at the head of the list.
node * remove(iterator &where)
extracts the current item from "where" and repairs the hole.
void append(iterator &where, node *new_node)
adds a "new_node" into the list immediately after "where".
void zap(iterator &where)
wipes out the item at "where", including its contents.
int items_from_tail(const iterator &where) const
Returns the number of elements between the current item and the tail.
void zap_all()
destroys all the list elements and makes the list empty.
void insert(iterator &where, node *new_node)
places a "new_node" immediately before the current node in the list.
bool set_index(iterator &to_set, int new_index)
positions the iterator "to_set" at the index specified.
An object representing the interstitial cell in most linked data structures.
void set_link(int link_number, node *new_link)
Connects the node "new_link" to this node.
int links() const
Returns the number of links the node currently holds.
void insert_link(int where, node *to_add=NULL_POINTER)
adds a new link prior to the position specified in "where".
node * get_link(int link_number) const
Returns the node that is connected to the specified "link_number".
#define NULL_POINTER
The value representing a pointer to nothing.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.