code apoemal

A bit of code from Windows for Shockwave 4.0, in development.
Depth-first recursive traversal of a tree.
Anything that can be done recursively can also be done iteratively, but
recursion often gives rise to more elegant and readable code.

on assembleTree theManagerSpritenum
–This returns a list of the spritenums of managers
–that are descendants of theManagerSpritenum, and the
–list also includes theManagerSpritenum at the start.
theResult=[theManagerSpriteNum]
if sprite(theManagerSpriteNum).pChildWindowList <> [] then
–pChildWindowList contains a list of the spritenums
–of managers that are children of the multi-sprite
–managed by theManagerSpriteNum.
repeat with i = 1 to sprite(theManagerSpriteNum).pChildWindowListCount
theResult=concatenateLists(theResult,
assembleTree(sprite(theManagerSpriteNum).pChildWindowList))
end repeat
end if
return theResult
end

on concatenateLists a, b
c=a.duplicate()
repeat with i=1 to b.count
c.add(b)
end repeat
return c
end