Implement stacks and queues in Lua using tables. Learn push/pop, the O(n) trap with table.remove(t, 1), and how to build an efficient circular buffer.
Tutorial series
Lua Data Structures
6 tutorials — follow in order for the best learning path.
- Stacks and Queues in Lua
- Implementing Sets in Lua
Learn how to implement and use sets in Lua using tables with true sentinel values, including set operations, iteration gotchas, 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 BSTs 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
Learn the two main ways to represent graphs in Lua: adjacency matrices and adjacency lists, with BFS and DFS implementations.