Linked Lists
Linked Lists
A linked list is a type of data structure. Because Articles/Table|tables
are dynamic entities, it is easy to implement linked lists in Lua. Each node is represented by a Articles/Table|table
and links are simply table fields that contain references to other Articles/Table|tables
.
Types of Lists
Basic Singly Linked
Here’s a basic linked list. Each node has two fields, next
(Articles/Table|table
) and value
(Articles/String|string
).
Circularly Linked
The circularly linked list is almost identical to the singly linked list, except you include a link from the last node to the first one. Be careful though, as it is possible to accidentally try to traverse it forever once inside a loop.
Here’s a circularly linked list. It’s slightly more complicated.
Doubly Linked List
Here’s a doubly linked list. It is significantly more complicated than the singly linked list.