2016-12-14 3 views
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"은 어떻게 함께 작동합니까?

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) 

답변

0

먼저 몇 가지 일반적인 알고리즘 구현을 통해 이동 더 나은, 당신은 아이디어를 얻을 것이다 : 나는 다음과 같은 방법을 추가 할 필요가

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; 
    } 

:

나는 생성자와 몇 가지 방법을 다음과 같이 시작 일반적인 알고리즘의 구현에 대해. 예를 들어 다음은 일반적인 정렬 알고리즘입니다.

Heap Sort

Insertion Sort

Selection Sort

Merge Sort

Quick Sort