0
現在、ジェネリックタイプの二項最小ヒーププライオリティキューを実装中です。ジェネリックタイプの二項最小ヒーププライオリティキュー
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;
}
}
}
あなたは私がジェネリック型PとKである。ここでの問題を持って見ての通り、私はどのように私のバイナリにジェネリック型を実装するには考えている:
私は、次のbinomialminheap.javaを与えていますヒープ。 "Entry"、 "Node"、 "BinomialHeap"はどのように連携しますか?
私は、次のコンストラクタといくつかのメソッドで始まった:
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;
}
私は、次のメソッドを追加する必要があります。あなたが最初のいくつかの一般的なアルゴリズムの実装を通過
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)