예제 #1
0
        // adding FibVertex to root list
        private void AddRoot(FibHeapVertex x)
        {
            roots.Add(x.id);

            if (roots.Count > 1)
            {
                vertexes[roots[0]].left = x.id;

                x.right = vertexes[roots[0]].id;

                vertexes[roots[roots.Count - 2]].right = x.id;

                x.left = vertexes[roots[roots.Count - 2]].id;
            }
        }
예제 #2
0
        // Inserting new Vertex into our Fib heap
        public void Insert(int key)
        {
            FibHeapVertex x = new FibHeapVertex();
            vertexes.Add(x);

            x.key = key;

            n++;
            last_id++;

            x.id = last_id;

            x.degree = 0;
            x.parent = -1;
            x.child = -1;

            x.left = last_id;
            x.right = last_id;

            if (key > max)
            {
                max = key;
                max_id = last_id;
            }

            AddRoot(x);
        }