public TElement Top() { if (heap.Min() != null) { return(heap.Min().Data); } else { return(default(TElement)); } }
public void FibonacciHeapPeekTest() { // small heap FibonacciHeap <Int32, String> heap = new FibonacciHeap <Int32, String>(); heap.Insert(0, "0"); heap.Peek.ShouldBe("0"); heap.Insert(1, "1"); heap.Peek.ShouldBe("0"); heap.Insert(-1, "-1"); heap.Peek.ShouldBe("-1"); // large heap heap = new FibonacciHeap <Int32, String>(); for (Int32 index = 0; index < this.values.Length; index++) { heap.Insert(this.values[index].Key, this.values[index].Value); heap.Peek.ShouldBe(heap.Min(item => item.Key).ToString()); heap.Peek.ShouldBe(this.values.Take(index + 1).Min(item => item.Key).ToString()); } // exceptions heap = new FibonacciHeap <Int32, String>(); String peek; Should.Throw <InvalidOperationException>(() => peek = heap.Peek); }
public T Dequeue() { var node = _heap.Min(); _heap.Delete(node); ////var e = m_items[0]; ////m_items[0] = m_items[--m_count]; ////// Restore heap if it was broken ////FixDown(0); ////// Once items count reaches one eighth of the queue ////// capacity it is reduced to half so that items ////// still occupy one fourth (if it is reduced when ////// count reaches one fourth after reduce items will ////// occupy half of queue capacity and next enqueued item ////// will require queue expand) ////if (m_count <= m_items.Length / 8) ////{ //// Expand(m_items.Length / 2); ////} return(node.Data); }
public void min() { var heap = new FibonacciHeap <int, double>(0); var node = new FibonacciHeapNode <int, double>(-1, 0); heap.Insert(node); while (!heap.IsEmpty()) { node = heap.Min(); heap.RemoveMin(); int n = node.Data; double timee = node.Key; if (n == -2) { continue; } var con = parameter[n]; foreach (var item in con) { //ListValueData.Add(item); int n1 = item.Key; // el node el connected beha double t1 = item.Value.Key; // el weight 3ala el edge double oldtime = ans[n1].Value.Key; double dist = item.Value.Value.Key; if (t1 + timee < oldtime) { var vip = new KeyValuePair <int, KeyValuePair <double, double> >(n, new KeyValuePair <double, double>(t1 + timee, dist)); ans[n1] = vip; var node2 = new FibonacciHeapNode <int, double>(n1, t1 + timee); heap.Insert(node2); } } } }
public TElement Top() { return(heap.Min().Data); }