示例#1
0
        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());
        }
示例#2
0
            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);
            }
示例#3
0
            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);
            }
示例#4
0
 public LockedBT(int data, LockedBT parent)
 {
     this.Parent = parent;
     this.Data   = data;
 }