[go: up one dir, main page]

Skip to content
MusNik edited this page Jun 22, 2020 · 6 revisions

ArrayList Class

Constructor:

new ArrayList⁠(⁠[⁠array⁠]⁠)

List struct build on top of an array.

Parameters:

Name Type Description
[array] *⁠[] Optional. Array to make the ArrayList from.

Members:

array : *[]

Can be used with an accessor or as a reference, points to the same array for full lifecycle.

Type: *[]

Methods:

add(...value)

Adds a new value to the ArrayList, will be added at the end.

Parameters:

Name Type Description
...value * Multiple. Value(s) to add to the ArrayList.

remove(pos)

Removes the value at a specific position within the ArrayList.

Parameters:

Name Type Description
pos real Position of value to delete.

insert(pos, value)

Adds the given value into the list at the given position, values after will be shifted.

Parameters:

Name Type Description
pos real Position to add the value from 0 to size-1.
value * Value to add to the list.

size()real

Returns the number of items in the ArrayList.

Returns: real

find_index(value)real

Checks the ArrayList for a value.

Parameters:

Name Type Description
value * Value to find.

Returns: real
Index of value found in ArrayList, -1 if value doesn't exist.

clear()

Clears all data from the ArrayList making array size to 0.

is_empty()bool

Checks the ArrayList to see if it is empty.

Returns: bool

sort(ascending)

Modifies the ArrayList, sorting it with the quicksort algorithm (strings sorted alphabetically).

Parameters:

Name Type Description
ascending bool Whether the values should be ascending (true) or descending (false) order.

swap(pos1, pos2)

Swaps the values in pos1 and pos2.

Parameters:

Name Type Description
pos1 real Position of value to swap with the value of pos2.
pos2 real Position of value to swap with the value of pos1.

shuffle()

Reorders all the values into random positions.

reverse()

Reverses the order of the elements in the ArrayList.

copy(source)

Copies the contents of one ArrayList into another.

Parameters:

Name Type Description
source ArrayList ArrayList to be copied from.

clone()ArrayList

Returns a shallow copy of this ArrayList.

Returns: ArrayList