public IEnumerable <bool> problem24() { LockedBT root = new LockedBT(12, null); root.Left = new LockedBT(10, root); root.Left.Left = new LockedBT(4, root.Left); root.Left.Right = new LockedBT(11, root.Left); root.Right = new LockedBT(15, root); root.Right.Left = new LockedBT(13, root.Right); yield return(root.isLocked()); root.Left.Left.@lock(); yield return(root.isLocked()); }
private bool canLockOrUnlock() { if (this.numOfLockedDescendant > 0) { return(false); } for (LockedBT curr = this.Parent; curr != null; curr = curr.Parent) { if (curr.isLocked()) { return(false); } } ; return(true); }
public bool unlock() { if (!this.isLocked()) { return(false); } if (!this.canLockOrUnlock()) { return(false); } for (LockedBT curr = this.Parent; curr != null; curr = curr.Parent) { curr.numOfLockedDescendant -= 1; } this.locked = false; return(true); }
public LockedBT(int data, LockedBT parent) { this.Parent = parent; this.Data = data; }