mirror of
https://github.com/rustomax/nim-stacks
synced 2026-01-09 06:31:11 +00:00
No description
|
|
||
|---|---|---|
| docs | ||
| src | ||
| tests | ||
| .gitignore | ||
| .travis.yml | ||
| LICENSE | ||
| README.md | ||
| stacks.nimble | ||
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