public PriorityQueue(int capacity, ITypeMath <TPriority> priorityMath)
        {
            if (capacity <= 0)
            {
                throw new ArgumentException("Capacity must be greater than zero");
            }

            this.capacity = capacity;
            queue         = new ItemPriority <TItem, TPriority> [capacity];

            this.priorityMath = priorityMath;
        }
        // Try to avoid unnecessary slow memory reallocations by creating your queue with an ample capacity
        private void ExpandCapacity()
        {
            // Double our capacity
            capacity *= 2;

            // Create a new queue
            var newQueue = new ItemPriority <TItem, TPriority> [capacity];

            // Copy the contents of the original queue to the new one
            Array.Copy(queue, newQueue, queue.Length);

            // Copy the new queue over the original one
            queue = newQueue;
        }
        public void Enqueue(TItem item, TPriority priority)
        {
            if (++count > capacity)
            {
                ExpandCapacity();
            }

            int newItemIndex = count - 1;

            queue[newItemIndex] = new ItemPriority <TItem, TPriority> {
                Item = item, Priority = priority
            };

            ReorderItem(newItemIndex, -1);
        }