Skip to content

nathanielketema/dsa-zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

121 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Structures and Algorithms (DSA) using zig

This codebase contains common data structures and algorithms in zig. It's tailored for beginners learning DSA or for programmers exploring the language.

Setup

To use these data structures and algorithms in your own codebase:

  1. Add this as a dependency in your build.zig.zon file:
zig fetch --save git+https://github.com/nathanielketema/dsa-zig.git
  1. 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"));
  1. Finally, you can use it by importing it to your code base:
const dsa = @import("dsa");

Documentation

This library comes with it's own documentation page.

To access the docs:

zig build docs

You can then use any static HTTP server to view the generated page.

  • example using http-server

    http-server zig-out/docs/

Example

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();
}

About

A Data Structures and Algorithms Library in zig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages