id |
ftwikibooks:enwikibooks:21897:120533
|
record_format |
openpolar
|
spelling |
ftwikibooks:enwikibooks:21897:120533 2023-10-29T02:40:41+01:00 Wikibooks: BlitzMax/Modules/Data structures/Linked lists https://en.wikibooks.org/wiki/BlitzMax/Modules/Data_structures/Linked_lists eng eng Book ftwikibooks 2023-10-02T17:47:34Z 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]] function. Add objects to a linked list using [[ListAddFirst]] or [[ListAddLast]]. Both functions return a link object which can be used to later remove the object with the [[RemoveLink]] function. You can also remove objects with the [[ListRemove]] function. 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. =Lists versus Arrays= It is important to keep in mind that index based access in a linked list is relatively slow. For each item that you wish to index the linked list must iterate through its internal links until it finds the requested index whereas an array can directly access any value at any position. So why use linked lists at all? you might ask. Inserting a value into the middle of an array is an expensive operation you must move all items after the insert position down in the array by one then insert the new value in the space created. In a linked list you must simply redirect the pointers between links and you have instantly inserted a value in the middle of the list. It is generally best to use a linked list when you need to make many changes to data and an array when you need to frequently access data at random. If you need to make many insertions and deletions to an array you can convert it to a list with [[ListFromArray]] and then convert the edited list back to an array with [[ListToArray]]. =Types= =TLink= Link Object used by TList hiddenh4 Methods Value NextLink PrevLink Remove =TLink Methods= hiddenh3 Value Method Value Object() Description Returns the Object associated with this Link. Example value.bmx Local list TList = New TList list.AddLast( Item 1 ) list.AddLast( Item 2 ) list.AddLast( Item 3 ) Local link TLink = list.FindLink( Item 2 ) Print String(link.Value()) hiddenh3 NextLink Method NextLink ... Book The Pointers WikiBooks - Open-content textbooks
|
institution |
Open Polar
|
collection |
WikiBooks - Open-content textbooks
|
op_collection_id |
ftwikibooks
|
language |
English
|
description |
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]] function. Add objects to a linked list using [[ListAddFirst]] or [[ListAddLast]]. Both functions return a link object which can be used to later remove the object with the [[RemoveLink]] function. You can also remove objects with the [[ListRemove]] function. 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. =Lists versus Arrays= It is important to keep in mind that index based access in a linked list is relatively slow. For each item that you wish to index the linked list must iterate through its internal links until it finds the requested index whereas an array can directly access any value at any position. So why use linked lists at all? you might ask. Inserting a value into the middle of an array is an expensive operation you must move all items after the insert position down in the array by one then insert the new value in the space created. In a linked list you must simply redirect the pointers between links and you have instantly inserted a value in the middle of the list. It is generally best to use a linked list when you need to make many changes to data and an array when you need to frequently access data at random. If you need to make many insertions and deletions to an array you can convert it to a list with [[ListFromArray]] and then convert the edited list back to an array with [[ListToArray]]. =Types= =TLink= Link Object used by TList hiddenh4 Methods Value NextLink PrevLink Remove =TLink Methods= hiddenh3 Value Method Value Object() Description Returns the Object associated with this Link. Example value.bmx Local list TList = New TList list.AddLast( Item 1 ) list.AddLast( Item 2 ) list.AddLast( Item 3 ) Local link TLink = list.FindLink( Item 2 ) Print String(link.Value()) hiddenh3 NextLink Method NextLink ...
|
format |
Book
|
title |
Wikibooks: BlitzMax/Modules/Data structures/Linked lists
|
spellingShingle |
Wikibooks: BlitzMax/Modules/Data structures/Linked lists
|
title_short |
Wikibooks: BlitzMax/Modules/Data structures/Linked lists
|
title_full |
Wikibooks: BlitzMax/Modules/Data structures/Linked lists
|
title_fullStr |
Wikibooks: BlitzMax/Modules/Data structures/Linked lists
|
title_full_unstemmed |
Wikibooks: BlitzMax/Modules/Data structures/Linked lists
|
title_sort |
wikibooks: blitzmax/modules/data structures/linked lists
|
url |
https://en.wikibooks.org/wiki/BlitzMax/Modules/Data_structures/Linked_lists
|
genre |
The Pointers
|
genre_facet |
The Pointers
|
_version_ |
1781069083763015680
|