|
| | CursorList (void) |
| | the empty list, in a space of its own
|
| | CursorList (std::shared_ptr< CursorSpace< T > > S) |
| | the empty list in the space \( S \), shared with other lists
|
| | CursorList (std::initializer_list< T > items) |
| | the list of the given items, in a space of its own
|
| | CursorList (const CursorList &other) |
| | a copy of the items of other, in the same space
|
| | CursorList (CursorList &&other) noexcept |
| | the cells of other, which is left empty in the same space
|
| CursorList & | operator= (CursorList other) noexcept |
| | the items of other, by copy and swap
|
| | ~CursorList () |
| | gives the cells back to the free list of the space
|
| void | swap (CursorList &other) noexcept |
| | exchanges the cells, and the spaces, with other
|
| bool | empty (void) const |
| | true if there is no item
|
| bool | finished (Pos p) const |
| | true on \( \mathit{pos}_{-1} = -1 \) and on \( \mathit{pos}_n \)
|
| Pos | head (void) const |
| | \( \mathit{pos}_0 \), i.e., 0
|
| Pos | tail (void) const |
| | the position of the last item, \( O( n ) \), by a scan as in SinglyList::tail()
|
| Pos | next (Pos p) const |
| | the position that follows \( p \)
|
| Pos | prev (Pos p) const |
| | the position that precedes \( p \), \( O( n ) \), by a scan as in SinglyList::prev()
|
| Pos | insert (Pos p, const T &v) |
| | puts \( v \) in the position \( p \), the new item taking the position \( p \)
|
| Pos | remove (Pos p) |
| | removes the item in the position \( p \), whose successor takes the position \( p \)
|
| const T & | read (Pos p) const |
| | the item in the position \( p \)
|
| void | write (Pos p, const T &v) |
| | writes \( v \) in the position \( p \)
|
| bool | operator== (const CursorList &o) const |
| | the same items in the same order
|
| const CursorSpace< T > & | space (void) const |
| | the space of the list
|
| long | first (void) const |
| | the cursor of the first cell, 0 if the list is empty
|
| iterator | begin (void) |
| | the iterator on the first item
|
| iterator | end (void) |
| | the iterator past the last item
|
| const_iterator | begin (void) const |
| | the constant iterator on the first item
|
| const_iterator | end (void) const |
| | the constant iterator past the last item
|
| const_iterator | cbegin (void) const |
| | the constant iterator on the first item
|
| const_iterator | cend (void) const |
| | the constant iterator past the last item
|
| template<std::input_iterator I, std::sentinel_for< I > S> |
| | CursorList (I first, S last) |
| | the list of the items of [ first , last ), in their order
|
| void | push_front (const T &v) |
| | \( v \) at the front, for std::front_inserter
|
template<class T>
class ADS::CursorList< T >
a SEQUENCE realized with cursors in a CursorSpace
puts \( v \) in the position \( p \), the new item taking the position \( p \)
In pseudocode (Aho, Hopcroft and Ullman, section 2.2), \( S \) the space and \( \ell \) the link that leads to the item in \( p \), i.e., \( S[ p ].\mathit{next} \), or the first cell if \( p = 0 \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insert}( p , v ) \cr
2 & \quad k \gets S.\mathrm{take}();\ S[ k ].\mathit{value} \gets v \cr
3 & \quad S[ k ].\mathit{next} \gets \ell;\ \ell \gets k \cr
4 & \quad \textbf{return}\ p
\end{array}}
\]
- Precondition
- \( p \) is not \( \mathit{pos}_{-1} \)
- Postcondition
- read( p ) is \( v \)
removes the item in the position \( p \), whose successor takes the position \( p \)
In pseudocode (Aho, Hopcroft and Ullman, section 2.2), \( \ell \) as in insert():
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{remove}( p ) \cr
2 & \quad k \gets \ell;\ \ell \gets S[ k ].\mathit{next}\quad
\triangleright\ \text{unlink the first cell} \cr
3 & \quad S.\mathrm{give}( k );\ \textbf{return}\ p
\end{array}}
\]
- Precondition
- \( p \) holds an item