Re: quad tree
- Posted by mic_ Aug 09, 2009
- 1197 views
A simple recursive depth-first traversal..
constant T = { {2,3,4,5, 1}, {0,6,0,0, 2}, {0,0,0,0, 3}, {0,0,0,0, 4}, {0,0,0,0, 5}, {0,0,0,0, 6} } procedure visit(sequence node) printf(1, "Visiting node %d\n", node[5]) end procedure procedure traverse(sequence tree, integer root, integer proc_id) for i = 1 to 4 do if tree[root][i] then -- Visit the i:th child node call_proc(proc_id, {tree[tree[root][i]]}) -- Traverse the subtree that begins with the child traverse(tree, tree[root][i], proc_id) end if end for end procedure traverse(T, 1, routine_id("visit"))
Not exactly optimal, but you get the idea.