Linked lists
A linked list allows you to efficiently add and remove objects to and from a collection of objects.
To create a linked list, use the CreateList command.
Add objects to a linked list using ListAddFirst or ListAddLast. Both commands return a link object which can be used to later remove the object with the RemoveLink command. You can also remove objects with the ListRemove command. However this is not as efficient as using RemoveLink because the list must first be searched for the object to be removed.
To visit all the objects in a linked list, you can use an EachIn loop.
Types
TLink | Link Object used by TList |
TListEnum | Enumerator Object use by TList in order to implement Eachin support. |
TList | Linked List |
Functions
Function reference
Function CreateList:TList() |
Returns | A new linked list object
|
Description | Create a linked list |
Example | ' createlist.bmx
' create a list to hold some objects
list:TList=createlist()
' add some string objects to the list
listaddlast list,"one"
listaddlast list,"two"
listaddlast list,"three"
' enumerate all the strings in the list
for a$=eachin list
print a$
next
|
Function ClearList( list:TList ) |
Description | Clear a linked list |
Information | Removes all objects from list.
|
Function CountList( list:TList ) |
Returns | The numbers of objects in list.
|
Description | Count list length |
Function ListIsEmpty( list:TList ) |
Returns | True if list is empty, else false
|
Description | Check if list is empty |
Function ListContains( list:TList,value:Object ) |
Returns | True if list contains value, else false
|
Description | Check if list contains a value |
Function SortList( list:TList,ascending=True,compareFunc( o1:Object,o2:Object ) ) |
Description | Sort a list |
Function ListFromArray:TList( arr:Object[] ) |
Returns | A new linked list
|
Description | Create a list from an array |
Function ListToArray:Object[]( list:TList ) |
Returns | An array of objects
|
Description | convert a list to an array |
Function SwapLists( list_x:TList,list_y:TList ) |
Description | Swap the contents of 2 lists |
Function ReverseList( list:TList ) |
Description | Reverse the order of elements of a list |
Function ListFindLink:TLink( list:TList,value:Object ) |
Returns | The link containting value
|
Description | Find a link in a list |
Function ListAddLast:TLink( list:TList,value:Object ) |
Returns | A link object
|
Description | Add an object to a linked list |
Function ListAddFirst:TLink( list:TList,value:Object ) |
Returns | A link object
|
Description | Add an object to a linked list |
Function ListRemove( list:TList,value:Object ) |
Description | Remove an object from a linked list |
Information | ListRemove scans a list for the specified value and removes its link.
|
Function RemoveLink( link:TLink ) |
Description | Remove an object from a linked list |
Information | RemoveLink is more efficient than ListRemove.
|