Friday, March 9, 2012

Connect all the nodes at the same level in a binary tree

1 comment:

  1. def con(Node n, int l, Node p) {
    if (n == null) return;
    l++;
    if (l == LEVEL) {
    if (p == null) p = n;
    else p.next = n;
    }

    p = con(n.left, l++, p);
    p = con(n.right, l++, p);

    return p;
    }

    ReplyDelete