Skip to content

Instantly share code, notes, and snippets.

@acolley
Last active December 27, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save acolley/7371049 to your computer and use it in GitHub Desktop.
Save acolley/7371049 to your computer and use it in GitHub Desktop.
type
TNode_S = ptr object
id: int
child_l: TNode_S
child_r: TNode_S
var
counter = 0
wurzel: TNode_S = nil
proc create_node(l: TNode_S, r: TNode_S): TNode_S =
result = cast[TNode_S](alloc0(sizeof(TNode_S)))
result.id = counter
result.child_l = l
result.child_r = r
inc(counter)
proc make_tree(depth: int): TNode_S =
if depth > 1:
result = create_node(make_tree(depth - 1), make_tree(depth - 1))
else:
result = create_node(nil, nil)
when isMainModule:
var num = 24
# benchmarking code can go here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment