/// <summary>Copies the elements stored in the queue to a new array.</summary> /// <returns>A new array containing a snapshot of elements copied from the queue.</returns> public KeyValuePair <TKey, TValue>[] ToArray() { lock (_syncLock) { if (_useMinHeap) { var clonedHeap = new MinBinaryHeap(_minHeap); var result = new KeyValuePair <TKey, TValue> [_minHeap.Count]; for (int i = 0; i < result.Length; i++) { result[i] = clonedHeap.Remove(); } return(result); } else { var clonedHeap = new MaxBinaryHeap(_maxHeap); var result = new KeyValuePair <TKey, TValue> [_maxHeap.Count]; for (int i = 0; i < result.Length; i++) { result[i] = clonedHeap.Remove(); } return(result); } } }