Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7807955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:00:49+00:00 2026-06-02T03:00:49+00:00

Possible Duplicate: Priority queue in .Net Is there an implementation of the Heap data

  • 0

Possible Duplicate:
Priority queue in .Net

Is there an implementation of the Heap data structure in .Net?

http://en.wikipedia.org/wiki/Heap_(data_structure)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:00:50+00:00Added an answer on June 2, 2026 at 3:00 am

    This class I’ve been working on might be useful for you. Obviously I give you no guarantees.

    public sealed class FibonacciHeap<TKey, TValue>
    {
        readonly List<Node> _root = new List<Node>();
        int _count;
        Node _min;
    
        public void Push(TKey key, TValue value)
        {
            Insert(new Node {
                Key = key,
                Value = value
            });
        }       
    
        public KeyValuePair<TKey, TValue> Peek()
        {
            if (_min == null)
                throw new InvalidOperationException();
            return new KeyValuePair<TKey,TValue>(_min.Key, _min.Value);
        }       
    
        public KeyValuePair<TKey, TValue> Pop()
        {
            if (_min == null)
                throw new InvalidOperationException();
            var min = ExtractMin();
            return new KeyValuePair<TKey,TValue>(min.Key, min.Value);
        }
    
        void Insert(Node node)
        {
            _count++;
            _root.Add(node);
            if (_min == null)
            {
                _min = node;
            }
            else if (Comparer<TKey>.Default.Compare(node.Key, _min.Key) < 0)
            {
                _min = node;
            }
        }
    
        Node ExtractMin()
        {
            var result = _min;
            if (result == null)
                return null;
            foreach (var child in result.Children)
            {
                child.Parent = null;
                _root.Add(child);
            }
            _root.Remove(result);
            if (_root.Count == 0)
            {
                _min = null;
            }
            else
            {
                _min = _root[0];
                Consolidate();
            }
            _count--;
            return result;
        }
    
        void Consolidate()
        {
            var a = new Node[UpperBound()];
            for (int i = 0; i < _root.Count; i++)
            {
                var x = _root[i];
                var d = x.Children.Count;
                while (true)
                {   
                    var y = a[d];
                    if (y == null)
                        break;                  
                    if (Comparer<TKey>.Default.Compare(x.Key, y.Key) > 0)
                    {
                        var t = x;
                        x = y;
                        y = t;
                    }
                    _root.Remove(y);
                    i--;
                    x.AddChild(y);
                    y.Mark = false;
                    a[d] = null;
                    d++;
                }
                a[d] = x;
            }
            _min = null;
            for (int i = 0; i < a.Length; i++)
            {
                var n = a[i];
                if (n == null)
                    continue;
                if (_min == null)
                {
                    _root.Clear();
                    _min = n;
                }
                else
                {
                    if (Comparer<TKey>.Default.Compare(n.Key, _min.Key) < 0)
                    {
                        _min = n;
                    }
                }
                _root.Add(n);
            }
        }
    
        int UpperBound()
        {
            return (int)Math.Floor(Math.Log(_count, (1.0 + Math.Sqrt(5)) / 2.0)) + 1;
        }
    
        class Node
        {
            public TKey Key;
            public TValue Value;
            public Node Parent;
            public List<Node> Children = new List<Node>();
            public bool Mark;
    
            public void AddChild(Node child)
            {
                child.Parent = this;
                Children.Add(child);
            }
    
            public override string ToString()
            {
                return string.Format("({0},{1})", Key, Value);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Priority queue in .Net This question is similar, but i want to
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Can a Bash script tell what directory it's stored in? Is there
Possible Duplicate: .NET Enumeration allows comma in the last field public enum SubPackageBackupModes {
Possible Duplicate: Create Generic method constraining T to an Enum Is there any reason
Possible Duplicate: Setting a thread priority in a service I've created a Windows Service
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: Is there a simple script to convert C++ enum to string? In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.