|
![](/i/fill.gif) |
On Sun, 24 Mar 2002 13:08:12 +0100, Tim Nikias wrote:
> Using the Current SDL, I think it would be possible to
> write a binary-tree-data-structure in a 1D-array. You'd
> probably have to use some loops or perhaps even
> recursive macros, but it can be done. If it must be proven,
> I'll do it, when I have some free time, because I think
> binary-tree-structures might be useful in many cases.
A binary tree can always be put in a 1-d array. It's simple: Given a
cell with index n, the left child of that cell is at index n*2 and
the right child of that cell is at index n*2+1. The parent of that
cell is, obviously, at index int(n/2). A few macros to implement that
scheme and there you go.
However, it would only be useful with numbers and strings and possibly
vectors (but for vectors you'd have to define a sort order.)
--
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbf 1}hollow interior{media{emission 3-T}}}#end
Z(-x-x.2x)camera{location z*-10rotate x*90normal{bumps.02scale.05}}
Post a reply to this message
|
![](/i/fill.gif) |