PureBasic - List

Overview

Lists (also known as linked-lists) are structures for storing data which are dynamically allocated depending of your need. It is a list of elements (the data you want to store) and each element is fully independent of the others. You can add as many elements you want (or as many as will fit into the memory of your computer), insert elements at the position you need, delete some other and more. This kind of data management is very useful as it's one of the best ways to handle data when you do not know how many elements you will need to store, or if you are often changing how many elements there are.

Before you can work with Lists, you must declare them first. This could be done with the keyword NewList. For saving the contents are also often used structures.

Lists can be sorted using SortList() or SortStructuredList(), and can also be randomized using RandomizeList().

To specifically search the contents of a List, using of loops is recommended: For : Next, ForEach : Next, Repeat : Until or While : Wend.

The first element is at position 0, the next at 1 and so on.

Other possibilities for storing data are the use of Arrays and Maps.

When using threads, the same list can not be accessed or modified at the same time in different threads. Mutexes can to be used to ensure the list is only used by one thread.

Command Index

AddElement
ChangeCurrentElement
ClearList
CopyList
CountList (deprecated)
DeleteElement
FirstElement
FreeList
InsertElement
LastElement
ListIndex
ListSize
MergeLists
MoveElement
NextElement
PopListPosition
PreviousElement
PushListPosition
ResetList
SelectElement
SplitList
SwapElements

Example

List.pb

Supported OS

All

Reference Manual - Index