0

I am currently implementing Binomial Min-Heap Priority Queue with generic types.

I have given the following binomialminheap.java:

class BinomialMinHeap <K extends Comparable<? super K>, P>
{

    public static class Entry <K, P> {
        private P priority;
        private K key;
        private Node<P, K> node;

        private Entry (K k, P p)
        {
            priority = p;
            key= k;
        }

        public P priority () { return priority; }
        public K key() { return key; }
    }

    private static class Node <K, P> {

        private Entry<K, P> entry;

        private Node<K, P> parent;
    .
        private Node<K, P> child;

        private Node<K, P> sibling;

        private int degree;

        private Node (Entry<K, P> e)
        {
            entry = e;
            e.node = this;
        }

        private P priority ()
        {
            return entry.priority;
        }
    }
}

As you see I have the generic types P and K. The problem here is, I have no idea how to implement the generics types into my binary heap. How do "Entry", "Node" and "BinomialHeap" work together?

I began with following constructor and few methods:

    private Node<P,D> Nodes;
    private int size;

    public BinomialMinHeap()
    {
        Nodes = null;
        size = 0;
    }

    public boolean isEmpty ()
    {
        return Nodes == null;
    }

    public int size()
    {
        return size;
    }

I have to add following methods:

boolean contains (Entry<K, P> e)
Entry<K, P> insert (K k, P p)
boolean changePriority (Entry<K, P> e, P p)
Entry<K, P> minimum ()
Entry<K, P> extractMinimum ()
boolean remove (Entry<K, P> e)

1 Answers1

0

Better you first go through some generic algorithm implementations, then you will get an idea about the implementation of generic algorithms. For example following are some generic sorting algorithms.

Heap Sort

Insertion Sort

Selection Sort

Merge Sort

Quick Sort

Hari Krishna
  • 3,658
  • 1
  • 36
  • 57