/// <summary>
        /// Removes a node at the specified position of the tail
        /// </summary>
        /// <param name="index">Index</param>
        /// <returns>Returns the node removed</returns>
        private PriorityDictionaryItem <TValue, TPriority> RemoveAt(int index)
        {
            PriorityDictionaryItem <TValue, TPriority> o   = items[index];
            PriorityDictionaryItem <TValue, TPriority> tmp = items[this.Count - 1];

            items[--this.Count] = default(PriorityDictionaryItem <TValue, TPriority>);
            if (this.Count > 0)
            {
                int i = index;
                int j = i + 1;
                while (i < Count / 2)
                {
                    if ((j < Count - 1) && (compareFunc(items[j].Priority, items[j + 1].Priority) > 0))
                    {
                        j++;
                    }
                    if (compareFunc(items[j].Priority, tmp.Priority) >= 0)
                    {
                        break;
                    }
                    items[i] = items[j];
                    i        = j;
                    j       *= 2;
                }
                items[i] = tmp;
            }

            return(o);
        }
        /// <summary>
        /// Copies the elements to an array
        /// </summary>
        /// <returns>Returns an array with the list of items in the queue</returns>
        public PriorityDictionaryItem <TValue, TPriority>[] ToArray()
        {
            PriorityDictionaryItem <TValue, TPriority>[] newItems = new PriorityDictionaryItem <TValue, TPriority> [this.Count];

            Array.Copy(items, newItems, this.Count);

            return(newItems);
        }
        /// <summary>
        /// Adds an item to the queue with a priority value
        /// </summary>
        /// <param name="value">Value to store</param>
        /// <param name="priority">Priority</param>
        public void Enqueue(TValue value, TPriority priority)
        {
            if (this.Count == capacity)
            {
                //Increase capacity
                this.Capacity = (int)(Capacity * 1.5);
            }

            // Create the new item
            PriorityDictionaryItem <TValue, TPriority> newItem = new PriorityDictionaryItem <TValue, TPriority>(value, priority);

            int i = this.Count++;

            while ((i > 0) && (compareFunc(items[i / 2].Priority, newItem.Priority) > 0))
            {
                items[i] = items[i / 2];
                i       /= 2;
            }

            items[i] = newItem;
        }