List
A List is a flexible collection that stores elements in a specific order using a doubly linked data structure. It allows efficient insertion and removal of items at both the front and back of the list, as well as sequential traversal using iterators. This class provides methods to add, remove, search, and iterate over elements, making it suitable for scenarios where dynamic, ordered collections are needed.
Usage
To use this class, add the following require at the top of your script:
Reference
new
Create a new List
Parameters
object(table) (optional)
Returns
List
pushBack
Push a value to the back of the list
Parameters
value(any)
popBack
Pop the last value from the list
Returns
any
pushFront
Push a value to the front of the list
Parameters
value(any)
popFront
Pop the first value from the list
Returns
any
front
Get the first value
Returns
any
back
Get the last value
Returns
any
empty
Check if the list is empty
Returns
boolean
clear
Remove all elements from the list
begin
Get an iterator to the beginning of the list
Returns
List_Iterator
end
Get an iterator to the end of the list
Returns
List_Iterator
find
Find a value starting from an iterator (or from beginning)
Parameters
v(any)start(List_Iterator) (optional)
Returns
List_Iterator|nil
findLast
Find a value starting from the end (or from a given iterator)
Parameters
v(any)start(List_Iterator) (optional)
Returns
List_Iterator|nil
erase
Erase the node at the iterator
Parameters
itr(List_Iterator)
Returns
List_Iterator
eraseValue
Erase the first occurrence of a value
Parameters
value(any)
eraseAll
Erase all occurrences of a value
Parameters
value(any)
insert
Insert a value after the iterator
Parameters
itr(List_Iterator)value(any)
Returns
List_Iterator|nil
insertBefore
Insert a value before the iterator
Parameters
itr(List_Iterator)value(any)
Returns
List_Iterator|nil
Print all elements (in reverse order)
size
Count the number of elements
Returns
number
clone
Create a clone of the list
Returns
List
Class: List
new
Create a new List
Parameters
object(table) (optional)
Returns
List
pushBack
Push a value to the back of the list
Parameters
value(any)
popBack
Pop the last value from the list
Returns
any
pushFront
Push a value to the front of the list
Parameters
value(any)
popFront
Pop the first value from the list
Returns
any
front
Get the first value
Returns
any
back
Get the last value
Returns
any
empty
Check if the list is empty
Returns
boolean
clear
Remove all elements from the list
begin
Get an iterator to the beginning of the list
Returns
List_Iterator
end
Get an iterator to the end of the list
Returns
List_Iterator
find
Find a value starting from an iterator (or from beginning)
Parameters
v(any)start(List_Iterator) (optional)
Returns
List_Iterator|nil
findLast
Find a value starting from the end (or from a given iterator)
Parameters
v(any)start(List_Iterator) (optional)
Returns
List_Iterator|nil
erase
Erase the node at the iterator
Parameters
itr(List_Iterator)
Returns
List_Iterator
eraseValue
Erase the first occurrence of a value
Parameters
value(any)
eraseAll
Erase all occurrences of a value
Parameters
value(any)
insert
Insert a value after the iterator
Parameters
itr(List_Iterator)value(any)
Returns
List_Iterator|nil
insertBefore
Insert a value before the iterator
Parameters
itr(List_Iterator)value(any)
Returns
List_Iterator|nil
Print all elements (in reverse order)
size
Count the number of elements
Returns
number
clone
Create a clone of the list
Returns
List