Skip to main content

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

NameDescription
=Assigns the value of the right-hand side to the left-hand side.
[]Accesses an element at the specified index.

Members

NameDescription
backReturns the last element in the container. Throws an exception if the container is empty.
capacityReturns the number of elements that the container has currently allocated space for.
clearClears all elements from the container.
containsChecks if the container contains an element with the specified value.
countReturns the number of occurrences of the specified value in the container.
emptyChecks if the container is empty.
eraseRemoves the first occurrence of the specified value from the container.
erase_atErases the element at the specified position in the container.
extendExtends the list by appending all elements from another list.
extendedInserts all elements from another list into a copy of this list.
frontReturns the first element in the list. Throws an exception if the list is empty.
indexReturns the index of the first occurrence of the specified value in the container.
index_maxReturns the index of the maximum element in the container. Throws an exception if the container is empty.
index_minReturns the index of the minimum element in the container. Throws an exception if the container is empty.
insertInserts a value at the end of the container.
insert_atInserts an element at the specified position in the container.
is_sortedChecks if the container is sorted in increasing order (comparison operator<).
maxReturns the maximum element in the container. Throws an exception if the container is empty.
minReturns the minimum element in the container. Throws an exception if the container is empty.
pop_backRemoves the last element from the container. Throws an exception if the container is empty.
push_backAppends an element to the end of the container.
replicateReplicates the container n times.
replicatedCreates a new container by replicating the original container n times.
reserveReserves storage for at least the specified number of elements.
resizeResizes the container to contain the specified number of elements.
reverseReverses the order of elements in the container. Returns the container itself.
reversedReturns a reversed copy of the the container.
sizeReturns the number of elements in the container.
sortSorts the container in place using the provided comparison function and returns the sorted container.
sortedReturns a sorted copy of the container.