public BinTree ToTree() { var tree = new BinTree(value, left, right); Zipper parent; while (Ancestors.TryPop(out parent)) { if (parent is ZipperLeft zl) { tree = new BinTree(zl.value, tree, zl.right); } else if (parent is ZipperRight zr) { tree = new BinTree(zr.value, zr.left, tree); } } return(tree); }
public Zipper Up() { Zipper parent; if (!Ancestors.TryPop(out parent)) { return(null); } var tree = new BinTree(value, left, right); if (parent is ZipperLeft zl) { zl.SetLeft(tree); } else if (parent is ZipperRight zr) { zr.SetRight(tree); } return(parent); }