Data structures · real, tested code

Implement a Stack and a Queue in Larzscript

The two most basic linear data structures - last-in-first-out and first-in-first-out - named explicitly instead of just using a bare list.

Both are built directly on the language's own list push()/pop(); the packages exist so the intent ("this is a stack", "this is a queue") reads clearly in real code.

larzscript pkg install stack
larzscript pkg install queue

Code

import "stack" as stack
import "queue" as queue

let s = stack.new()
stack.push(s, 1); stack.push(s, 2); stack.push(s, 3)
print("stack pop:", stack.pop(s))

let q = queue.new()
queue.enqueue(q, 1); queue.enqueue(q, 2); queue.enqueue(q, 3)
print("queue dequeue:", queue.dequeue(q))
Output
stack pop: 3
queue dequeue: 1