private TItem[] ToArray()
        {
            var cloneHeap = new MinDHeap <MinPriorityQueueNode>(2, _minHeap.Items, _comparer);
            var result    = new TItem[cloneHeap.Count];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = cloneHeap.RemoveRoot().Data;
            }
            return(result);
        }
 /// <summary>
 /// Initialises a new instance of <see cref="SynchronisedMinPriorityQueue{TItem, TPriority}"/> with specified
 /// queue size and specified priority comparer.
 /// </summary>
 /// <param name="priorityComparer">The <see cref="IComparer{T}"/> to use when comparing 2 priorities.</param>
 /// <param name="initialQueueSize">The initial size of the queue.</param>
 /// <exception cref="ArgumentNullException"><paramref name="priorityComparer"/> was null.</exception>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="initialQueueSize"/> was less than 1.</exception>
 public SynchronisedMinPriorityQueue(IComparer <TPriority> priorityComparer, int initialQueueSize)
 {
     if (priorityComparer == null)
     {
         throw new ArgumentNullException(nameof(priorityComparer),
                                         $"Unable to initialise Minimum Priority-Queue. {nameof(priorityComparer)} cannot be null.");
     }
     if (initialQueueSize <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(initialQueueSize),
                                               $"Unable to initialise Minimum Priority-Queue. {nameof(initialQueueSize)} must be greater than zero.");
     }
     _comparer = new SynchronisedMinPriorityQueueNodeComparer(priorityComparer);
     _minHeap  = new MinDHeap <SynchronisedMinPriorityQueueNode>(2, initialQueueSize, _comparer);
 }