On Jul 21, 2011, at 8:21 AM, Intransition wrote:
> Basic example, let's use this class:
>=20
>  class CaseObject
>    attr :case
>    def initialize(parent_case)
>      @case =3D parent_case
>    end
>  end
>=20
> And this has been defined:
>=20
>  c1 =3D CaseObject.new(nil)
>  c11 =3D CaseObject.new(c1)
>  c12 =3D CaseObject.new(c1)
>  c121 =3D CaseObject.new(c12)
>  c122 =3D CaseObject.new(c12)
>  d1 =3D CaseObject.new(nil)
>  d11 =3D CaseObject.new(d1)
>  d12 =3D CaseObject.new(d1)

This is already a tree.

> Then I am given all the _leaf_ nodes in a list:
>=20
>  [c11, c121, c122, d11, d12]

You won't need to rebuild the original tree if you have bidirectional =
links.

class CaseObject
  def initialize parent
    @case =3D parent
    @children =3D []
    parent.add self if parent
  end

  def add child
    @children << child
  end
end

Walking the tree up or down is simple when you can walk both up and down =
so the exercise is left to the reader.

Also, there's no relationship between the d nodes and the c nodes.=