Exemplo n.º 1
0
        public TVertex Dequeue()
        {
            FibonacciHeapCell <TDistance, TVertex> cell = _heap.Top;

            if (cell is null)
            {
                throw new InvalidOperationException("Queue is empty.");
            }

            _heap.Dequeue();
            return(cell.Value);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public IEnumerator <KeyValuePair <TPriority, TValue> > GetEnumerator()
        {
            var tempHeap   = new FibonacciHeap <TPriority, TValue>(Direction, PriorityComparison);
            var cellsStack = new Stack <FibonacciHeapCell <TPriority, TValue> >();

            _cells.ForEach(x => cellsStack.Push(x));
            while (cellsStack.Count > 0)
            {
                FibonacciHeapCell <TPriority, TValue> topCell = cellsStack.Peek();
                tempHeap.Enqueue(topCell.Priority, topCell.Value);
                cellsStack.Pop();
                topCell.Children?.ForEach(x => cellsStack.Push(x));
            }

            while (!tempHeap.IsEmpty)
            {
                yield return(tempHeap.Top.ToKeyValuePair());

                tempHeap.Dequeue();
            }
        }