No description
Find a file
Max Skybin 3562d2d98c
Update README.md
Remove travisci build status
2024-12-03 23:28:39 -05:00
docs Add popUnsafe, peek, peekUnsafe 2020-10-09 21:08:25 +03:00
src Add popUnsafe, peek, peekUnsafe 2020-10-09 21:08:25 +03:00
tests Update tests for unsafe methods 2021-01-04 19:44:47 -05:00
.gitignore Initial commit 2019-09-14 19:59:39 -04:00
.travis.yml Added travis CI check 2019-09-14 23:16:41 -04:00
LICENSE Initial commit 2019-09-14 19:46:55 -04:00
README.md Update README.md 2024-12-03 23:28:39 -05:00
stacks.nimble Add popUnsafe, peek, peekUnsafe 2020-10-09 21:08:25 +03:00

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