This codebase contains common data structures and algorithms in zig. It's tailored for beginners learning DSA or for programmers exploring the language.
To use these data structures and algorithms in your own codebase:
- Add this as a dependency in your
build.zig.zonfile:
zig fetch --save git+https://github.com/nathanielketema/dsa-zig.git- Next step is to add it to your
build.zig:
const dsa = b.dependency("dsa_zig", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("dsa", dsa.module("dsa"));- Finally, you can use it by importing it to your code base:
const dsa = @import("dsa");This library comes with it's own documentation page.
To access the docs:
zig build docsYou can then use any static HTTP server to view the generated page.
-
example using
http-serverhttp-server zig-out/docs/
Using a Stack:
const std = @import("std");
const dsa = @import("dsa");
const Stack = dsa.Stack;
pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer assert(gpa.deinit() == .ok);
const allocator = gpa.allocator();
var stack: Stack(u8) = .init(allocator);
defer stack.deinit();
try stack.push(1);
try stack.push(2);
try stack.push(3);
_ = stack.pop();
}