Beispiel #1
0
        public T ExtractTop()
        {
            TopNode.Validate(x => x != null, new ArgumentException("The collection is empty."));
            var top = TopNode;

            if (top != null)
            {
                if (top.Child != null)
                {
                    var children = GetSiblingsOf(top.Child);
                    foreach (var childNode in children)
                    {
                        AddNode(childNode, TopNode);
                        childNode.Parent = null;
                    }
                }
                RemoveNode(top);
                if (ReferenceEquals(top, top.Right))
                {
                    TopNode = null;
                }
                else
                {
                    TopNode = TopNode.Right;
                    Consolidate();
                }
                Count--;
            }

            return(top.Value);
        }