BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›LinkedList

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
  • BRL.BMPLoader
  • Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • BRL.FileSystem
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • BRL.JPGLoader
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
    • TIntMap
    • TIntKey
    • TPtrMap
    • TPtrKey
    • TStringMap
  • BRL.Math
  • Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PNGLoader
  • BRL.PolledInput
  • Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI
  • BRL.RamStream
  • Random

    • Introduction
    • TRandom

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • BRL.TGALoader
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I

    Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Text

    Format

    • Introduction
    • TFormatter

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

PUB

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • Pub.xmmintrin
  • Pub.ZLib

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister
    • TNoSuchAlgorithmException

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLDisplayMode
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType
Edit

BRL.LinkedList

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

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

Functions

Function CreateList:TList()

Create a linked list

Returns

A new linked list object

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local 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 Local a:String = EachIn list
    Print a
Next


Function ClearList( list:TList )

Clear a linked list

Removes all objects from list.

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' print amount of elements in the list
Print CountList(list)

' clear the list and remove all elements
ClearList(list)

' print amount of elements in the list
Print CountList(list)

' outputs:
' 3
' 0


Function CountList( list:TList )

Count list length

Returns

The numbers of objects in list.

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' print amount of elements in the list
Print CountList(list)

' outputs:
' 3


Function ListIsEmpty( list:TList )

Check if list is empty

Returns

True if list is empty, else false

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' check if the list contains some elements
If ListIsEmpty(list) Then
    Print "list is empty"
Else
    Print "list contains elements"
EndIf

' outputs:
' list contains elements


Function ListContains( list:TList,value:Object )

Check if list contains a value

Returns

True if list contains value, else false

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' check if the list contains some elements
If ListContains(list, "four") Then
    Print "four"
EndIf

If ListContains(list, "three") Then
    Print "three"
EndIf

' outputs:
' three


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

Sort a list

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "short")
ListAddLast(list, "longer")
ListAddLast(list, "the longest")


' DEFAULT SORT
' sort them (in this case this leads to an alphabetic sort)
' second parameter sets sort to ascending or not
SortList(list, True)

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' longer
' short
' the longest


' CUSTOM SORT
' define a custom compare function
Function MyCompare:Int( o1:Object, o2:Object )
    If Len(String(o1)) < Len(String(o2)) Then
        Return -1 ' o1 before o2
    ElseIf Len(String(o1)) > Len(String(o2)) Then
        Return 1 ' o1 after o2
    Else
        Return 0 ' equal
    EndIf
End Function

' sort them with a custom compare function
SortList(list, True, MyCompare)

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' short
' longer
' the longest


Function ListFromArray:TList( arr:Object[] )

Create a list from an array

Returns

A new linked list

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create an array holding some objects
Local objects:Object[] = ["one", "two", "three"]

' create a linked list out of the elements
Local list:TList = ListFromArray(objects) 

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' one
' two
' three


Function ListToArray:Object[]( list:TList )

convert a list to an array

Returns

An array of objects

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' create an array out of the list elements
Local objects:Object[] = ListToArray(list) 

' enumerate all the strings in the array
For Local a:String = EachIn objects
    Print a
Next

' outputs:
' one
' two
' three


Function SwapLists( list_x:TList,list_y:TList )

Swap the contents of 2 lists

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")


' create a second list
Local list2:TList = CreateList()
ListAddLast(list2, "four")
ListAddLast(list2, "five")
ListAddLast(list2, "six")


' swap the lists
SwapLists(list, list2)

' enumerate all the strings in the first list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' four
' five
' six


Function ReverseList( list:TList )

Reverse the order of elements of a list

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' reverse the list
ReverseList(list)

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' three
' two
' one


Function ListFindLink:TLink( list:TList,value:Object )

Find a link in a list

Returns

The link containting value

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the begin of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' find the TLink instance of the element/object "two" 
Local link:TLink = ListFindLink(list, "two")

' remove the element from the list by utilizing the link
ListRemoveLink(list, link)

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' one
' three


Function ListRemoveLink( list:TList,link:TLink )

Remove an object from a linked list referenced by a link

ListRemoveLink removes an object from the linked list referenced by the given link

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the begin of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' find the TLink instance of the element/object "two" 
Local link:TLink = ListFindLink(list, "two")

' remove the element from the list by utilizing the link
ListRemoveLink(list, link)

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' one
' three


Function ListAddLast:TLink( list:TList,value:Object )

Add an object to a linked list

Returns

A link object

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the end of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' one
' two
' three


Function ListGetFirst:Object( list:TList )

Returns the first object in the list

Returns Null if the list is empty.


Function ListGetLast:Object( list:TList )

Returns the last object in the list

Returns Null if the list is empty.


Function ListAddFirst:TLink( list:TList,value:Object )

Add an object to a linked list

Returns

A link object

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the begin of the list
ListAddFirst(list, "one")
ListAddFirst(list, "two")
ListAddFirst(list, "three")

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' three
' two
' one


Function ListRemoveFirst:Object( list:TList )

Removes and returns the first object in the list.

Returns Null if the list is empty.


Function ListRemoveLast:Object( list:TList )

Removes and returns the last object in the list.

Returns Null if the list is empty.


Function ListRemove( list:TList,value:Object )

Remove an object from a linked list

ListRemove scans a list for the specified value and removes its link.

Example

SuperStrict

Framework Brl.LinkedList
Import Brl.StandardIO

' create a list to hold some objects
Local list:TList = CreateList()

' add some string objects to the begin of the list
ListAddLast(list, "one")
ListAddLast(list, "two")
ListAddLast(list, "three")

' remove the string "two"
ListRemove(list, "two")

' enumerate all the strings in the list
For Local a:String = EachIn list
    Print a
Next

' outputs:
' one
' three


← BRL.KeyCodesTList →
  • Types
  • Functions
    • Function CreateList:TList()
    • Function ClearList( list:TList )
    • Function CountList( list:TList )
    • Function ListIsEmpty( list:TList )
    • Function ListContains( list:TList,value:Object )
    • Function SortList( list:TList,ascending=True,compareFunc( o1:Object,o2:Object ) )
    • Function ListFromArray:TList( arr:Object[] )
    • Function ListToArray:Object[]( list:TList )
    • Function SwapLists( list_x:TList,list_y:TList )
    • Function ReverseList( list:TList )
    • Function ListFindLink:TLink( list:TList,value:Object )
    • Function ListRemoveLink( list:TList,link:TLink )
    • Function ListAddLast:TLink( list:TList,value:Object )
    • Function ListGetFirst:Object( list:TList )
    • Function ListGetLast:Object( list:TList )
    • Function ListAddFirst:TLink( list:TList,value:Object )
    • Function ListRemoveFirst:Object( list:TList )
    • Function ListRemoveLast:Object( list:TList )
    • Function ListRemove( list:TList,value:Object )
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2022 Bruce A Henderson