BRL.LinkedList: Types Functions Source  


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

TLinkLink Object used by TList
TListEnumEnumerator Object use by TList in order to implement Eachin support.
TListLinked List

Functions

CreateListCreate a linked list
ClearListClear a linked list
CountListCount list length
ListIsEmptyCheck if list is empty
ListContainsCheck if list contains a value
SortListSort a list
ListFromArrayCreate a list from an array
ListToArrayconvert a list to an array
SwapListsSwap the contents of 2 lists
ReverseListReverse the order of elements of a list
ListFindLinkFind a link in a list
ListAddLastAdd an object to a linked list
ListAddFirstAdd an object to a linked list
ListRemoveRemove an object from a linked list
RemoveLinkRemove an object from a linked list

Function reference

Function CreateList:TList()
ReturnsA new linked list object
DescriptionCreate 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 )
DescriptionClear a linked list
InformationRemoves all objects from list.

Function CountList( list:TList )
ReturnsThe numbers of objects in list.
DescriptionCount list length

Function ListIsEmpty( list:TList )
ReturnsTrue if list is empty, else false
DescriptionCheck if list is empty

Function ListContains( list:TList,value:Object )
ReturnsTrue if list contains value, else false
DescriptionCheck if list contains a value

Function SortList( list:TList,ascending=True,compareFunc( o1:Object,o2:Object ) )
DescriptionSort a list

Function ListFromArray:TList( arr:Object[] )
ReturnsA new linked list
DescriptionCreate a list from an array

Function ListToArray:Object[]( list:TList )
ReturnsAn array of objects
Descriptionconvert a list to an array

Function SwapLists( list_x:TList,list_y:TList )
DescriptionSwap the contents of 2 lists

Function ReverseList( list:TList )
DescriptionReverse the order of elements of a list

Function ListFindLink:TLink( list:TList,value:Object )
ReturnsThe link containting value
DescriptionFind a link in a list

Function ListAddLast:TLink( list:TList,value:Object )
ReturnsA link object
DescriptionAdd an object to a linked list

Function ListAddFirst:TLink( list:TList,value:Object )
ReturnsA link object
DescriptionAdd an object to a linked list

Function ListRemove( list:TList,value:Object )
DescriptionRemove an object from a linked list
InformationListRemove scans a list for the specified value and removes its link.

Function RemoveLink( link:TLink )
DescriptionRemove an object from a linked list
InformationRemoveLink is more efficient than ListRemove.