Beispiel #1
0
        public int Pop()
        {
            if (IsEmpty)
            {
                throw new KeyNotFoundException("Heap is empty");
            }

            int value;

            if (ListA.Count > 0 && ListB.Count > 0)
            {
                if (ListA[0] <= ListB[0])
                {
                    value = ListA[0];
                    ListA.RemoveAt(0);
                }
                else
                {
                    value = ListB[0];
                    ListB.RemoveAt(0);
                }
            }
            else if (ListA.Count > 0)
            {
                value = ListA[0];
                ListA.RemoveAt(0);
            }
            else
            {
                value = ListB[0];
                ListB.RemoveAt(0);
            }

            return(value);
        }