3 ms·
Tree *a = new Leaf(); Tree *b = new Leaf(); Tree *c = new Node(a, b); a.parent = b.parent = c; null has other uses, e.g. as above for cyclically dependen
by 0xfaded 10y ago
Tree *a = new Leaf();
Tree *b = new Leaf();
Tree *c = new Node(a, b);
a.parent = b.parent = c;
null has other uses, e.g. as above for cyclically dependent initialisation.
- kazagistar 10y agoFirst, to some extent, your code is more a demonstration of the weakness of imperative vs declarative code, since, for example, Haskell lets you declare recursive structures directly, since it doesn't enforce an order of execution where none is needed. data Tree = Leaf Tree | Node Tree Tree a = Leaf c b = Leaf c c = Node a b But more importantly, there is no reason you can't do this with Optionals. Tree *a = new Leaf(); Tree *b = new Leaf(); Tree *c = new Node(a, b); a.parent = b.parent = new Some(c);