Build efficient stacks and queues in Lua using plain tables. Covers push and pop, the O(n) trap of table.remove(t, 1), and circular buffer performance.
Tutorial series
Lua Data Structures
6 tutorials — follow in order for the best learning path.
- Stacks and Queues in Lua: Implementations and Performance
- Implementing Sets in Lua Using Tables and Metatables
Hands-on guide to implementing sets in Lua: table keys as members, true sentinel values, union, intersection, difference, and read-only proxies.
- Singly and Doubly Linked Lists in Lua
Learn how to implement singly and doubly linked lists in Lua using tables, with performance comparisons and practical examples.
- Binary trees and binary search trees in Lua
Learn how to implement binary trees and binary search trees in Lua with clear explanations and runnable code examples.
- Priority Queues and Heaps in Lua
Learn how to implement priority queues and binary heaps in Lua using tables, with practical examples for task scheduling and event queues.
- Graph Representations in Lua: Adjacency Matrix and List
Learn two standard graph representations in Lua: adjacency matrices for dense graphs and adjacency lists for sparse graphs, with BFS and DFS traversal examples.