a double ended queue whose items are contiguous, rebuilt in the middle of its vector when they reach an end
More...
|
| | ContiguousDeque (void)=default |
| | the empty deque, with no places
|
| | ContiguousDeque (std::initializer_list< T > l) |
| | the items of l, in order
|
| | ContiguousDeque (const ContiguousDeque &o) |
| | a copy of o
|
| | ContiguousDeque (ContiguousDeque &&o) noexcept |
| | the vector of o, which is left empty with no places
|
| ContiguousDeque & | operator= (ContiguousDeque o) noexcept |
| | the items of o, by copy and swap
|
| | ~ContiguousDeque () |
| | destroys the items and frees the places
|
| void | swap (ContiguousDeque &o) noexcept |
| | exchanges the vector with that of o
|
| bool | empty (void) const |
| | true if there is no item
|
| std::size_t | size (void) const |
| | the number \( n \) of items
|
| std::size_t | capacity (void) const |
| | the number \( c \) of places
|
| T & | operator[] (std::size_t i) |
| | the item of rank \( i \), \( A[ h + i ] \)
|
| const T & | operator[] (std::size_t i) const |
| | the item of rank \( i \), constant
|
| T & | front (void) |
| | the first item
|
| T & | back (void) |
| | the last item
|
| T * | data (void) |
| | the items, contiguous
|
| const T * | data (void) const |
| | the items, contiguous and constant
|
| void | insert (std::size_t i, const T &x) |
| | puts \( x \) at the rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time
|
| void | erase (std::size_t i) |
| | removes the item of rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time
|
| void | push_front (const T &x) |
| | \( x \) at the front, \( O( 1 ) \) amortized
|
| void | push_back (const T &x) |
| | \( x \) at the back, \( O( 1 ) \) amortized
|
| void | pop_front (void) |
| | removes the first item
|
| void | pop_back (void) |
| | removes the last item
|
| void | clear (void) |
| | removes all the items, the places kept
|
| bool | operator== (const ContiguousDeque &o) const |
| | the same items in the same order
|
| 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
|
| reverse_iterator | rbegin (void) |
| | the iterator on the last item, backwards
|
| reverse_iterator | rend (void) |
| | the iterator before the first item, backwards
|
template<class T>
class ADS::ContiguousDeque< T >
a double ended queue whose items are contiguous, rebuilt in the middle of its vector when they reach an end
removes the item of rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time
In pseudocode (Morin, exercise 2.8):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{erase}( i ) \cr
2 & \quad \textbf{if}\ i < n / 2\ \textbf{then}\ A[ h + 1 .. h + i ]
\gets A[ h .. h + i - 1 ];\ h \gets h + 1 \cr
3 & \quad \textbf{else}\ A[ h + i .. h + n - 2 ] \gets A[ h + i + 1 .. h
+ n - 1 ] \cr
4 & \quad n \gets n - 1 \cr
5 & \quad \textbf{if}\ c > 9 n + 24\ \textbf{then}\ \mathrm{rebuild}()
\end{array}}
\]
- Precondition
- \( i < n \)
- Postcondition
- one item less
puts \( x \) at the rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time
In pseudocode (Morin, exercise 2.8), \( A[ 0 .. c - 1 ] \) the vector:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( i , x ) \cr
2 & \quad \textbf{if}\ i < n / 2\ \textbf{then} \cr
3 & \qquad \textbf{if}\ h = 0\ \textbf{then}\ \mathrm{rebuild}() \cr
4 & \qquad A[ h - 1 .. h + i - 2 ] \gets A[ h .. h + i - 1 ];
\ h \gets h - 1 \cr
5 & \quad \textbf{else} \cr
6 & \qquad \textbf{if}\ h + n = c\ \textbf{then}\ \mathrm{rebuild}() \cr
7 & \qquad A[ h + i + 1 .. h + n ] \gets A[ h + i .. h + n - 1 ] \cr
8 & \quad A[ h + i ] \gets x;\ n \gets n + 1
\end{array}}
\]
- Precondition
- \( i \le n \)
- Postcondition
- one item more, \( x \) at the rank \( i \)