Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.57 KB | None | 0 0
  1. from sequtils import newSeqWith
  2.  
  3. type
  4.   Forrest = ref object
  5.     parents, heights: seq[Natural]
  6.  
  7. proc newForrestv1(n: Natural): Forrest =
  8.   var
  9.     p = newSeqOfCap[Natural](n + 1)
  10.     h = newSeqOfCap[Natural](n + 1)
  11.  
  12.   for i in 0 .. n:
  13.     p[i] = i
  14.     h[i] = 1
  15.  
  16.   return Forrest(parents: p, heights: h)
  17.  
  18. proc newForrestv2(n: Natural): Forrest =
  19.   for i in 0 .. n:
  20.     result.parents[i] = i
  21.     result.heights[i] = 1
  22.  
  23. proc newForrestv3(n: Natural): Forrest =
  24.   result = new Forrest
  25.   for i in 0 .. n:
  26.     result.parents[i] = i
  27.     result.heights[i] = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement