0PricingLogin
Zig Academy · Lesson

A Generic Stack from Scratch

Type-parametric LIFO over an allocator.

What a Stack Does

A stack is a LIFO collection: the last item you push is the first one you pop. Think of plates piled on a counter. 🍽️

Make It Generic

To hold any element type, write a function that takes a type and returns a struct type. Each call gives a stack tailored to that type.

fn Stack(comptime T: type) type {
    return struct {};
}

All lessons in this course

  1. A Generic Stack from Scratch
  2. A Singly Linked List
  3. Using HashMap and AutoHashMap
  4. Profiling and Safety Trade-offs
← Back to Zig Academy