ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::List< T, Pooled > Class Template Reference

a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled More...

#include <ADS/sequence/List.h>

Classes

struct  Cell
 a cell of the list: the sentinel is a Cell with no meaningful value More...
class  Iterator
 the iterator, on items const if Const More...

Public types

using Item = T
 the type of the items
using Pos = Cell *
 a position is the address of a cell
using value_type = T
 the type of the items
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances
using reference = T &
 a reference to an item
using const_reference = const T &
 a constant reference to an item
using iterator = Iterator< false >
 the iterator on the items
using const_iterator = Iterator< true >
 the iterator on the constant items
using reverse_iterator = std::reverse_iterator< iterator >
 the iterator on the items, backwards
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 the iterator on the constant items, backwards

Public member functions

 List (void)
 the empty list: the sentinel alone, its own predecessor and successor
 List (std::initializer_list< T > items)
 the list of the given items, in their order
template<std::input_iterator I, std::sentinel_for< I > S>
 List (I first, S last)
 the list of the items of [ first , last ), in their order
 List (const List &other)
 a copy of other, cell by cell
 List (List &&other) noexcept
 the cells of other, which is left empty, in \( O( 1 ) \) time
List & operator= (List other) noexcept
 the items of other, by copy and swap
 ~List ()
 frees the cells
void swap (List &other) noexcept
 exchanges the cells with other, relinking them to the sentinels in \( O( 1 ) \) time
bool empty (void) const
 true if the list is empty, i.e., the sentinel is its own successor
bool finished (Pos p) const
 true if \( p \) is \( \mathit{pos}_{-1} \) or \( \mathit{pos}_n \), i.e., the sentinel
Pos head (void) const
 the position of the first item
Pos tail (void) const
 the position of the last item
Pos next (Pos p) const
 the position of the item that follows \( p \)
Pos prev (Pos p) const
 the position of the item that precedes \( p \)
Pos insert (Pos p, const T &v)
 puts \( v \) in the position \( p \), i.e., before the item in \( p \), and returns its position
Pos remove (Pos p)
 removes the item in the position \( p \), returning the position of its successor, which is now in its place
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 List &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
const_iterator cbegin (void) const
 the constant iterator on the first item
const_iterator cend (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
const_reverse_iterator rbegin (void) const
 the constant iterator on the last item, backwards
const_reverse_iterator rend (void) const
 the constant iterator before the first item, backwards
void push_back (const T &v)
 \( v \) at the end, for std::back_inserter
void push_front (const T &v)
 \( v \) at the front, for std::front_inserter
std::size_t size (void) const
 the number \( n \) of items, kept
Pos position (std::size_t i) const
 the cell of rank \( i \), the sentinel for \( i = n \), reached from the nearer end in \( O( 1 + \min\{ i , n - i \} ) \) (Morin's getNode( i ))
const T & get (std::size_t i) const
 the item of rank \( i \), \( O( 1 + \min\{ i , n - i \} ) \)
T set (std::size_t i, const T &x)
 \( x \) written at the rank \( i \), the old item returned, \( O( 1 + \min\{ i , n - i \} ) \)
void add (std::size_t i, const T &x)
 \( x \) put at the rank \( i \), before the cell of rank \( i \), \( O( 1 + \min\{ i , n - i \} ) \)
T erase (std::size_t i)
 removes the item of rank \( i \) and returns it, \( O( 1 + \min\{ i , n - i \} ) \)
void checkSize (void) const
 counts the cells and throws std::logic_error if they are not the size kept (exercise 3.5 of Morin's book), \( O( n ) \)
bool isPalindrome (void) const
 true if the item of rank \( i \) equals that of rank \( n - 1 - i \) for every \( i \), by two walks from the two ends, \( \lfloor n / 2 \rfloor \) comparisons at most (exercise 3.7 of Morin's book)
void rotate (std::size_t r)
 the item of rank \( i \) moved to the rank \( ( i + r ) \bmod n \) by moving the sentinel before the item of rank \( n - r \), in \( O( 1 + \min\{ r , n - r \} ) \), no item moved and no cell made (exercise 3.8 of Morin's book)
List truncate (std::size_t i)
 the items of ranks \( i , \ldots , n - 1 \) cut off into the list returned, in \( O( 1 + \min\{ i , n - i \} ) \) by relinking (exercise 3.9 of Morin's book; in \( O( 1 + n - i ) \) by moving the items if Pooled)
void absorb (List &l2)
 the items of l2 appended to this list in their order, l2 left empty, in \( O( 1 ) \) by relinking (exercise 3.10 of Morin's book; in \( O( \log n ) \) if Pooled, the pool of l2 taken)
List deal (void)
 the items of odd rank moved, in their order, to the list returned (exercise 3.11 of Morin's book), \( O( n ) \)
void reverse (void)
 the order of the items reversed, by exchanging the two links of each cell and of the sentinel, \( O( n ) \) (exercise 3.12 of Morin's book)
void takeFirst (List &l2)
 the first cell of l2 moved to the end of this list, by relinking (a new cell with the item moved if Pooled), \( O( 1 ) \) (exercise 3.13 of Morin's book)
template<class C = std::less<>>
void mergeSort (C less=C())
 sorts the list, stable, by the merge sort of exercise 3.13 of Morin's book: the list cut in two halves by a walk to its middle, each sorted recursively and the two merged, all on the cells of this list, which are relinked and never copied, \( O( n \log n ) \) time and \( O( \log n ) \) space for the recursion [see ListSort.h for the natural merge sort of the runs, bottom up]

Static public member functions

template<class C = std::less<>>
static List merge (List &l1, List &l2, C less=C())
 the merge of the two sorted lists l1 and l2, which are left empty, stable (the items of l1 first among equal ones), in \( O( |l1| + |l2| ) \) (exercise 3.13 of Morin's book)

Detailed description

template<class T, bool Pooled = true>
class ADS::List< T, Pooled >

a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled

Member typedef documentation

◆ const_iterator

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::const_iterator = Iterator< true >

the iterator on the constant items

◆ const_reference

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::const_reference = const T &

a constant reference to an item

◆ const_reverse_iterator

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::const_reverse_iterator = std::reverse_iterator< const_iterator >

the iterator on the constant items, backwards

◆ difference_type

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::difference_type = std::ptrdiff_t

the type of the distances

◆ Item

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::Item = T

the type of the items

◆ iterator

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::iterator = Iterator< false >

the iterator on the items

◆ Pos

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::Pos = Cell *

a position is the address of a cell

◆ reference

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::reference = T &

a reference to an item

◆ reverse_iterator

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::reverse_iterator = std::reverse_iterator< iterator >

the iterator on the items, backwards

◆ size_type

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T, bool Pooled = true>
using ADS::List< T, Pooled >::value_type = T

the type of the items

Constructor and destructor documentation

◆ List() [1/5]

template<class T, bool Pooled = true>
ADS::List< T, Pooled >::List ( void )

the empty list: the sentinel alone, its own predecessor and successor

◆ List() [2/5]

template<class T, bool Pooled = true>
ADS::List< T, Pooled >::List ( std::initializer_list< T > items)

the list of the given items, in their order

◆ List() [3/5]

template<class T, bool Pooled = true>
template<std::input_iterator I, std::sentinel_for< I > S>
ADS::List< T, Pooled >::List ( I first,
S last )

the list of the items of [ first , last ), in their order

◆ List() [4/5]

template<class T, bool Pooled = true>
ADS::List< T, Pooled >::List ( const List< T, Pooled > & other)

a copy of other, cell by cell

◆ List() [5/5]

template<class T, bool Pooled = true>
ADS::List< T, Pooled >::List ( List< T, Pooled > && other)
noexcept

the cells of other, which is left empty, in \( O( 1 ) \) time

◆ ~List()

template<class T, bool Pooled = true>
ADS::List< T, Pooled >::~List ( )

frees the cells

Member function documentation

◆ absorb()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::absorb ( List< T, Pooled > & l2)

the items of l2 appended to this list in their order, l2 left empty, in \( O( 1 ) \) by relinking (exercise 3.10 of Morin's book; in \( O( \log n ) \) if Pooled, the pool of l2 taken)

Precondition
l2 is not this list

◆ add()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::add ( std::size_t i,
const T & x )

\( x \) put at the rank \( i \), before the cell of rank \( i \), \( O( 1 + \min\{ i , n - i \} ) \)

Precondition
\( i \le n \)
Postcondition
one item more, \( x \) at the rank \( i \)

◆ begin() [1/2]

template<class T, bool Pooled = true>
iterator ADS::List< T, Pooled >::begin ( void )
inlinenodiscard

the iterator on the first item

◆ begin() [2/2]

template<class T, bool Pooled = true>
const_iterator ADS::List< T, Pooled >::begin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cbegin()

template<class T, bool Pooled = true>
const_iterator ADS::List< T, Pooled >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class T, bool Pooled = true>
const_iterator ADS::List< T, Pooled >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ checkSize()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::checkSize ( void ) const

counts the cells and throws std::logic_error if they are not the size kept (exercise 3.5 of Morin's book), \( O( n ) \)

◆ deal()

template<class T, bool Pooled = true>
List ADS::List< T, Pooled >::deal ( void )
nodiscard

the items of odd rank moved, in their order, to the list returned (exercise 3.11 of Morin's book), \( O( n ) \)

In pseudocode (Morin, exercise 3.11):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{deal}() \cr 2 & \quad L \gets \text{an empty list};\ p \gets s.\mathit{succ} \cr 3 & \quad \textbf{while}\ p \ne s\ \textbf{and}\ p.\mathit{succ} \ne s\ \textbf{do} \cr 4 & \qquad q \gets p.\mathit{succ};\ \text{unlink } q;\ \text{link } q \text{ at the end of } L;\ p \gets p.\mathit{succ} \cr 5 & \quad \textbf{return}\ L \end{array}} \]

Postcondition
\( \lceil n / 2 \rceil \) items left

◆ empty()

template<class T, bool Pooled = true>
bool ADS::List< T, Pooled >::empty ( void ) const
nodiscard

true if the list is empty, i.e., the sentinel is its own successor

◆ end() [1/2]

template<class T, bool Pooled = true>
iterator ADS::List< T, Pooled >::end ( void )
inlinenodiscard

the iterator past the last item

◆ end() [2/2]

template<class T, bool Pooled = true>
const_iterator ADS::List< T, Pooled >::end ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ erase()

template<class T, bool Pooled = true>
T ADS::List< T, Pooled >::erase ( std::size_t i)

removes the item of rank \( i \) and returns it, \( O( 1 + \min\{ i , n - i \} ) \)

Precondition
\( i < n \)
Postcondition
one item less

◆ finished()

template<class T, bool Pooled = true>
bool ADS::List< T, Pooled >::finished ( Pos p) const
nodiscard

true if \( p \) is \( \mathit{pos}_{-1} \) or \( \mathit{pos}_n \), i.e., the sentinel

◆ get()

template<class T, bool Pooled = true>
const T & ADS::List< T, Pooled >::get ( std::size_t i) const
nodiscard

the item of rank \( i \), \( O( 1 + \min\{ i , n - i \} ) \)

Precondition
\( i < n \)

◆ head()

template<class T, bool Pooled = true>
Pos ADS::List< T, Pooled >::head ( void ) const
nodiscard

the position of the first item

◆ insert()

template<class T, bool Pooled = true>
Pos ADS::List< T, Pooled >::insert ( Pos p,
const T & v )

puts \( v \) in the position \( p \), i.e., before the item in \( p \), and returns its position

In pseudocode (section 4.1), a new cell \( t \) linked between \( p \) and its predecessor, which the sentinel guarantees:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( p , v )\quad \triangleright \ \text{before the cell } p \cr 2 & \quad t \gets \text{a new cell of value } v;\ q \gets p.\mathit{pred} \cr 3 & \quad t.\mathit{succ} \gets p;\ t.\mathit{pred} \gets q \cr 4 & \quad q.\mathit{succ} \gets t;\ p.\mathit{pred} \gets t\quad \triangleright\ \text{the sentinel if } q \text{ or } p \text{ is none} \cr 5 & \quad \textbf{return}\ t \end{array}} \]

Precondition
\( p \) is a position of this list (an audit)
Postcondition
the list is not empty, the result precedes \( p \) and holds \( v \)

◆ isPalindrome()

template<class T, bool Pooled = true>
bool ADS::List< T, Pooled >::isPalindrome ( void ) const
nodiscard

true if the item of rank \( i \) equals that of rank \( n - 1 - i \) for every \( i \), by two walks from the two ends, \( \lfloor n / 2 \rfloor \) comparisons at most (exercise 3.7 of Morin's book)

In pseudocode (Morin, exercise 3.7):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{isPalindrome}() \cr 2 & \quad p \gets s.\mathit{succ};\ q \gets s.\mathit{pred} \cr 3 & \quad \textbf{for}\ k \gets 1\ \textbf{to}\ \lfloor n / 2 \rfloor\ \textbf{do} \cr 4 & \qquad \textbf{if}\ p.\mathit{value} \ne q.\mathit{value} \ \textbf{then return false} \cr 5 & \qquad p \gets p.\mathit{succ};\ q \gets q.\mathit{pred} \cr 6 & \quad \textbf{return true} \end{array}} \]

◆ merge()

template<class T, bool Pooled = true>
template<class C = std::less<>>
List ADS::List< T, Pooled >::merge ( List< T, Pooled > & l1,
List< T, Pooled > & l2,
C less = C() )
staticnodiscard

the merge of the two sorted lists l1 and l2, which are left empty, stable (the items of l1 first among equal ones), in \( O( |l1| + |l2| ) \) (exercise 3.13 of Morin's book)

In pseudocode (Morin, exercise 3.13):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{merge}( l_1 , l_2 ) \cr 2 & \quad L \gets \text{an empty list} \cr 3 & \quad \textbf{while}\ l_1 \ne \emptyset\ \textbf{and}\ l_2 \ne \emptyset\ \textbf{do} \cr 4 & \qquad \textbf{if}\ \mathrm{first}( l_2 ) < \mathrm{first}( l_1 ) \ \textbf{then}\ L.\mathrm{takeFirst}( l_2 )\ \textbf{else} \ L.\mathrm{takeFirst}( l_1 ) \cr 5 & \quad L.\mathrm{absorb}( l_1 );\ L.\mathrm{absorb}( l_2 ); \ \textbf{return}\ L \end{array}} \]

Precondition
l1 and l2 sorted by less
Postcondition
the result sorted (an audit)

◆ mergeSort()

template<class T, bool Pooled = true>
template<class C = std::less<>>
void ADS::List< T, Pooled >::mergeSort ( C less = C())

sorts the list, stable, by the merge sort of exercise 3.13 of Morin's book: the list cut in two halves by a walk to its middle, each sorted recursively and the two merged, all on the cells of this list, which are relinked and never copied, \( O( n \log n ) \) time and \( O( \log n ) \) space for the recursion [see ListSort.h for the natural merge sort of the runs, bottom up]

In pseudocode (Morin, exercise 3.13):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{mergeSort}( L ) \cr 2 & \quad \textbf{if}\ |L| \le 1\ \textbf{then return} \cr 3 & \quad R \gets L.\mathrm{truncate}( \lfloor |L| / 2 \rfloor ) \cr 4 & \quad \mathrm{mergeSort}( L );\ \mathrm{mergeSort}( R ) \cr 5 & \quad L \gets \mathrm{merge}( L , R ) \end{array}} \]

Postcondition
the list sorted (an audit)

◆ next()

template<class T, bool Pooled = true>
Pos ADS::List< T, Pooled >::next ( Pos p) const
nodiscard

the position of the item that follows \( p \)

Precondition
\( p \) is a position of this list

◆ operator=()

template<class T, bool Pooled = true>
List & ADS::List< T, Pooled >::operator= ( List< T, Pooled > other)
noexcept

the items of other, by copy and swap

◆ operator==()

template<class T, bool Pooled = true>
bool ADS::List< T, Pooled >::operator== ( const List< T, Pooled > & o) const
nodiscard

the same items in the same order

◆ position()

template<class T, bool Pooled = true>
Pos ADS::List< T, Pooled >::position ( std::size_t i) const
nodiscard

the cell of rank \( i \), the sentinel for \( i = n \), reached from the nearer end in \( O( 1 + \min\{ i , n - i \} ) \) (Morin's getNode( i ))

In pseudocode (Morin, section 3.2), \( s \) the sentinel:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{position}( i ) \cr 2 & \quad \textbf{if}\ i < n / 2\ \textbf{then}\ p \gets s.\mathit{succ};\ \textbf{repeat}\ i\ \text{ times: } p \gets p.\mathit{succ} \cr 3 & \quad \textbf{else}\ p \gets s;\ \textbf{repeat}\ n - i \ \text{ times: } p \gets p.\mathit{pred} \cr 4 & \quad \textbf{return}\ p \end{array}} \]

Precondition
\( i \le n \)

◆ prev()

template<class T, bool Pooled = true>
Pos ADS::List< T, Pooled >::prev ( Pos p) const
nodiscard

the position of the item that precedes \( p \)

Precondition
\( p \) is a position of this list

◆ push_back()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::push_back ( const T & v)

\( v \) at the end, for std::back_inserter

◆ push_front()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::push_front ( const T & v)

\( v \) at the front, for std::front_inserter

◆ rbegin() [1/2]

template<class T, bool Pooled = true>
reverse_iterator ADS::List< T, Pooled >::rbegin ( void )
inlinenodiscard

the iterator on the last item, backwards

◆ rbegin() [2/2]

template<class T, bool Pooled = true>
const_reverse_iterator ADS::List< T, Pooled >::rbegin ( void ) const
inlinenodiscard

the constant iterator on the last item, backwards

◆ read()

template<class T, bool Pooled = true>
const T & ADS::List< T, Pooled >::read ( Pos p) const
nodiscard

the item in the position \( p \)

Precondition
\( p \) holds an item of this list

◆ remove()

template<class T, bool Pooled = true>
Pos ADS::List< T, Pooled >::remove ( Pos p)

removes the item in the position \( p \), returning the position of its successor, which is now in its place

In pseudocode (section 4.1), the cell unlinked from its two neighbors:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( p ) \cr 2 & \quad q \gets p.\mathit{pred};\ t \gets p.\mathit{succ} \cr 3 & \quad q.\mathit{succ} \gets t;\ t.\mathit{pred} \gets q\quad \triangleright\ p \text{ is out of the chain} \cr 4 & \quad \text{free the cell } p;\ \textbf{return}\ t \end{array}} \]

Precondition
\( p \) holds an item of this list (an audit)
Postcondition
the result follows the old predecessor of \( p \)

◆ rend() [1/2]

template<class T, bool Pooled = true>
reverse_iterator ADS::List< T, Pooled >::rend ( void )
inlinenodiscard

the iterator before the first item, backwards

◆ rend() [2/2]

template<class T, bool Pooled = true>
const_reverse_iterator ADS::List< T, Pooled >::rend ( void ) const
inlinenodiscard

the constant iterator before the first item, backwards

◆ reverse()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::reverse ( void )

the order of the items reversed, by exchanging the two links of each cell and of the sentinel, \( O( n ) \) (exercise 3.12 of Morin's book)

Postcondition
the items in the reverse order (an audit)

◆ rotate()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::rotate ( std::size_t r)

the item of rank \( i \) moved to the rank \( ( i + r ) \bmod n \) by moving the sentinel before the item of rank \( n - r \), in \( O( 1 + \min\{ r , n - r \} ) \), no item moved and no cell made (exercise 3.8 of Morin's book)

In pseudocode (Morin, exercise 3.8), \( r \) reduced modulo \( n \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{rotate}( r ) \cr 2 & \quad \textbf{if}\ r = 0\ \textbf{then return} \cr 3 & \quad u \gets \mathrm{position}( n - r ) \cr 4 & \quad \text{unlink } s;\ \text{link } s \text{ between } u.\mathit{pred} \text{ and } u \end{array}} \]

◆ set()

template<class T, bool Pooled = true>
T ADS::List< T, Pooled >::set ( std::size_t i,
const T & x )

\( x \) written at the rank \( i \), the old item returned, \( O( 1 + \min\{ i , n - i \} ) \)

Precondition
\( i < n \)

◆ size()

template<class T, bool Pooled = true>
std::size_t ADS::List< T, Pooled >::size ( void ) const
inlinenodiscard

the number \( n \) of items, kept

◆ swap()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::swap ( List< T, Pooled > & other)
noexcept

exchanges the cells with other, relinking them to the sentinels in \( O( 1 ) \) time

◆ tail()

template<class T, bool Pooled = true>
Pos ADS::List< T, Pooled >::tail ( void ) const
nodiscard

the position of the last item

◆ takeFirst()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::takeFirst ( List< T, Pooled > & l2)

the first cell of l2 moved to the end of this list, by relinking (a new cell with the item moved if Pooled), \( O( 1 ) \) (exercise 3.13 of Morin's book)

Precondition
l2 is not empty and is not this list

◆ truncate()

template<class T, bool Pooled = true>
List ADS::List< T, Pooled >::truncate ( std::size_t i)
nodiscard

the items of ranks \( i , \ldots , n - 1 \) cut off into the list returned, in \( O( 1 + \min\{ i , n - i \} ) \) by relinking (exercise 3.9 of Morin's book; in \( O( 1 + n - i ) \) by moving the items if Pooled)

In pseudocode (Morin, exercise 3.9):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{truncate}( i ) \cr 2 & \quad u \gets \mathrm{position}( i );\ L \gets \text{an empty list} \cr 3 & \quad \textbf{if}\ u \ne s\ \textbf{then}\ \text{link } u , \ldots , s.\mathit{pred} \text{ between the ends of } L;\ \text{link } u.\mathit{pred} \text{ to } s \cr 4 & \quad |L| \gets n - i;\ n \gets i;\ \textbf{return}\ L \end{array}} \]

Precondition
\( i \le n \)
Postcondition
\( i \) items left

◆ write()

template<class T, bool Pooled = true>
void ADS::List< T, Pooled >::write ( Pos p,
const T & v )

writes \( v \) in the position \( p \)

Precondition
\( p \) holds an item of this list (an audit)
Postcondition
read( p ) is \( v \)

The documentation for this class was generated from the following file: