stacks

Pure Nim stack implementation based on sequences.

Pure Nim score 30/100 · tests present · docs generated

Summary

Latest Version Unknown
License MIT
CI Status Passing
Downloads 0
Last Indexed 2026-07-22 05:28

Installation

nimble install stacks
choosenim install stacks
git clone https://github.com/rustomax/nim-stacks

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
stacks - - - - - - -

Source

Repository https://github.com/rustomax/nim-stacks
Homepage https://github.com/rustomax/nim-stacks
Documentation View Documentation
Registry Source nimble_official

README

nim-stacks

Pure Nim stack implementation based on sequences

Version 0.4.2

Installation

nimble install stacks

Example

import stacks

proc isPaired*(s: string): bool =
    ## Algorithm to detect unbalanced brackets using a stack
    var stack = Stack[char]()

    for c in s:
        case c:
            of '{': stack.push('}')
            of '[': stack.push(']')
            of '(': stack.push(')')
            of '}', ']', ')':
                if stack.isEmpty or stack.pop() != c: return false
            else: discard

    stack.isEmpty()

when isMainModule:
    assert isPaired("(((185 + 223.85) * 15) - 543)/2") == true
    assert isPaired("for (i = 1; i < 11; ++i)\n{printf(\"i\");}\nreturn 0;}\n}") == false