; ; ------------------------------------------------------------ ; ; PureBasic - Linked list example file ; ; (c) Fantaisie Software ; ; ------------------------------------------------------------ ; Structure BasicStructure Field1.b Field2.w Field3.l EndStructure Structure ComplexStructure Field1.b *Basic.BasicStructure ; Pointer to a BasicStructure object Basic2.BasicStructure ; Creation of the BasicStructure object inside this structure *Next.ComplexStructure ; Pointer to another ComplexStructure object EndStructure NewList TestList.BasicStructure() ; ;-------- Add Elements and TestLists -------- ; AddElement(TestList()) TestList()\Field2 = 1 AddElement(TestList()) TestList()\Field2 = 2 AddElement(TestList()) TestList()\Field2 = 3 AddElement(TestList()) TestList()\Field2 = 4 ; ;-------- MessageRequester("Number of elements in the list:", Str(TestList()\Field2), 0) -------- ; MessageRequester("Number of elements in the list:", Str(ListSize(TestList())), 0) ; First way to list all the elements ; ResetList(TestList()) ; Reset the list index before the first element. While NextElement(TestList()) ; Process all the elements... MessageRequester("List elements :", "Field2 value : "+Str(TestList()\Field2), 0) Wend ; Second way, with the help of ForEach ; ForEach TestList() ; Process all the elements... MessageRequester("List elements :", "Field2 value : "+Str(TestList()\Field2), 0) Next SelectElement(TestList(), 2) ; Go directly to the 3rd element MessageRequester("3rd Element", "Field2 value : "+Str(TestList()\Field2), 0) MessageRequester("Linked List - Example", "Finished", 0) End