List
A dynamic array that can grow and shrink in size during runtime.
List is a sequence container that stores elements in a contiguous memory layout. It provides fast random access to elements via indexing, andefficient insertion and removal at the end. List can store any type of value and automatically resize as needed. They are ideal for situations where you need an ordered collection with fast access by index and don't know the final size in advance.
Example
var numbers = [1,2,3]
numbers.push_back(4)
print("Size: ${numbers}")
print("First element: ${numbers[0]}")
print("Last element: ${numbers.back()}")
for (var i = 0; i < numbers.size(); ++i) {
print("Element ${i}: ${numbers[i]}")
}
Constructors
List() -> List
Creates a default-constructed instance of List.
List(const List other) -> List
Creates a copy of an existing List object.
Parameters
- other: The List object to copy.
Symbols
| Name | Description |
|---|---|
= | Assigns the value of the right-hand side to the left-hand side. |
[] | Accesses an element at the specified index. |
Members
| Name | Description |
|---|---|
| back | Returns the last element in the container. Throws an exception if the container is empty. |
| capacity | Returns the number of elements that the container has currently allocated space for. |
| clear | Clears all elements from the container. |
| contains | Checks if the container contains an element with the specified value. |
| count | Returns the number of occurrences of the specified value in the container. |
| empty | Checks if the container is empty. |
| erase | Removes the first occurrence of the specified value from the container. |
| erase_at | Erases the element at the specified position in the container. |
| extend | Extends the list by appending all elements from another list. |
| extended | Inserts all elements from another list into a copy of this list. |
| front | Returns the first element in the list. Throws an exception if the list is empty. |
| index | Returns the index of the first occurrence of the specified value in the container. |
| index_max | Returns the index of the maximum element in the container. Throws an exception if the container is empty. |
| index_min | Returns the index of the minimum element in the container. Throws an exception if the container is empty. |
| insert | Inserts a value at the end of the container. |
| insert_at | Inserts an element at the specified position in the container. |
| is_sorted | Checks if the container is sorted in increasing order (comparison operator<). |
| max | Returns the maximum element in the container. Throws an exception if the container is empty. |
| min | Returns the minimum element in the container. Throws an exception if the container is empty. |
| pop_back | Removes the last element from the container. Throws an exception if the container is empty. |
| push_back | Appends an element to the end of the container. |
| replicate | Replicates the container n times. |
| replicated | Creates a new container by replicating the original container n times. |
| reserve | Reserves storage for at least the specified number of elements. |
| resize | Resizes the container to contain the specified number of elements. |
| reverse | Reverses the order of elements in the container. Returns the container itself. |
| reversed | Returns a reversed copy of the the container. |
| size | Returns the number of elements in the container. |
| sort | Sorts the container in place using the provided comparison function and returns the sorted container. |
| sorted | Returns a sorted copy of the container. |