class LinkedList<ValueType>
list
type.
Available since: 2014/07/01 version of C++ library
Constructor | ||
O(1) | Initializes a new empty list. | |
Methods | ||
O(1) | Adds a new value to the end of this list. | |
O(N) | Removes all elements from this list. | |
O(N) | Returns true if the two lists contain the same elements in the same order. |
|
O(N) | Returns the element at the specified index in this list. | |
O(N) | Inserts the element into this list before the specified index. | |
O(1) | Returns true if this list contains no elements. |
|
O(N) | Calls the specified function on each element of the linkedlist in ascending index order. | |
O(N) | Removes the element at the specified index from this list. | |
O(N) | Replaces the element at the specified index in this list with a new value. | |
O(1) | Returns the number of elements in this list. | |
O(N) | Returns a new list containing elements from a sub-range of this list. | |
O(N) | Converts the list to a printable string representation. | |
Operators | ||
O(N) | Overloads [] to select elements from this list. |
|
O(N) | Concatenates two lists. | |
O(N) | Adds all of the elements from list2 to list1 . |
|
O(1) | Adds the single specified value to the list. | |
O(1) | Adds multiple values to the list. | |
O(N) | Returns true if list1 and list2 contain the same elements. |
|
O(N) | Returns true if list1 and list2 are different. |
|
O(N) | Outputs the contents of the list to the given output stream. | |
O(N) | Reads the contents of the given input stream into the list. |
LinkedList();
Usage:
LinkedList<ValueType> list;
void add(ValueType value); void push_back(ValueType value);
list
class in the Standard Template Library,
this method is also called push_back
.
Usage:
list.add(value);
void clear();
O(N) because it must loop over the underlying list nodes to free their memory.
Usage:
list.clear();
bool equals(const LinkedList& list) const;
true
if the two lists contain exactly the same element values in the same order.
Identical in behavior to the ==
operator.
Usage:
if (list.equals(list2)) ...
const ValueType& get(int index) const;
O(1) at front or end of list; O(N) average/worst case.
Usage:
ValueType val = list.get(index);
void insert(int index, ValueType value);
O(1) at front or end of list; O(N) average/worst case.
Usage:
list.insert(0, value);
bool isEmpty() const;
true
if this list contains no elements.
Usage:
if (list.isEmpty()) ...
void mapAll(void (*fn)(ValueType)) const; void mapAll(void (*fn)(const ValueType&)) const; void mapAll(FunctorType fn) const;
Usage:
list.mapAll(fn);
void remove(int index);
O(1) at front or end of list; O(N) average/worst case.
Usage:
list.remove(index);
void set(int index, ValueType value);
O(1) at front or end of list; O(N) average/worst case.
Usage:
list.set(index, value);
int size() const;
Usage:
int nElems = list.size();
LinkedList subList(int start, int length) const;
Usage:
LinkedList<ValueType> sub = list.subList(start, length);
Available since: 2014/10/20 version of C++ library
string toString() const;
"{value1, value2, value3}"
.
Usage:
string str = list.toString();
ValueType& operator[](int index); const ValueType& operator[](int index) const;
[]
to select elements from this list.
This extension enables the use of traditional array notation to
get or set individual elements. This method signals an error if
the index is outside the array range. The file supports two
versions of this operator, one for const
lists and
one for mutable lists.
O(1) at front or end of list; O(N) average/worst case.
Usage:
vec[index]
LinkedList operator+(const LinkedList& v2) const;
Usage:
v1 + v2
LinkedList& operator+=(const LinkedList& list2); LinkedList& operator+=(ValueType value);
v2
(or the single
specified value) to v1
. As a convenience, the
LinkedList
package also overloads the comma operator so
that it is possible to initialize a list like this:
LinkedList<int> digits; digits += 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
Usage:
list1 += list2; list1 += value;
LinkedList& operator,(ValueType value);
Usage:
list.mapAll(fn);