Package placement
Class MaxPairingHeap<T extends Comparable<T>>
java.lang.Object
placement.MaxPairingHeap<T>
- All Implemented Interfaces:
MaxPriorityQueue<T>
public class MaxPairingHeap<T extends Comparable<T>> extends Object implements MaxPriorityQueue<T>
Implements a pairing heap. Supports a increaseKey operation. Note that all
"matching" is based on the compareTo method. Based on implementation by Mark
Allen Weiss from the book "Data Stuctures & Algorithm Analysis in Java" -
Prentice Hall 1999
-
Constructor Summary
Constructors Constructor Description MaxPairingHeap()Construct the pairing heap.MaxPairingHeap(MaxPairingHeap<T> h1, MaxPairingHeap<T> h2)Construct the pairing heap by merging h1 and h2. -
Method Summary
Modifier and Type Method Description voidadd(PNode<T> p)voidadd(T x)Insert into the priority queue, and return a PNode that can be used by decreaseKey.TdeleteMax()Remove the biggest item from the priority queue.TfindMax()Find the biggest item in the priority queue.ArrayList<T>getAll()voidincreaseKey(PNode<T> p, T newVal)Change the value of the item stored in the pairing heap.booleanisEmpty()Test if the priority queue is logically empty.static voidmain(String[] args)voidmakeEmpty()Make the priority queue logically empty.voidmerge(MaxPriorityQueue<T> b)intsize()StringtoString()
-
Constructor Details
-
MaxPairingHeap
public MaxPairingHeap()Construct the pairing heap. -
MaxPairingHeap
Construct the pairing heap by merging h1 and h2.
-
-
Method Details
-
add
Insert into the priority queue, and return a PNode that can be used by decreaseKey. Duplicates are allowed.- Specified by:
addin interfaceMaxPriorityQueue<T extends Comparable<T>>- Parameters:
x- the item to insert.
-
add
-
findMax
Find the biggest item in the priority queue.- Specified by:
findMaxin interfaceMaxPriorityQueue<T extends Comparable<T>>- Returns:
- the biggest item, or null if empty.
-
deleteMax
Remove the biggest item from the priority queue.- Specified by:
deleteMaxin interfaceMaxPriorityQueue<T extends Comparable<T>>- Returns:
- the biggest item, or null if empty.
-
increaseKey
Change the value of the item stored in the pairing heap. Does nothing if newVal is larger than the currently stored value.- Parameters:
p- any PNode returned by addItem.newVal- the new value, which must be bigger than the currently stored value.
-
isEmpty
public boolean isEmpty()Test if the priority queue is logically empty.- Returns:
- true if empty, false otherwise.
-
makeEmpty
public void makeEmpty()Make the priority queue logically empty. -
getAll
- Specified by:
getAllin interfaceMaxPriorityQueue<T extends Comparable<T>>
-
toString
-
main
-
merge
- Specified by:
mergein interfaceMaxPriorityQueue<T extends Comparable<T>>
-
size
public int size()- Specified by:
sizein interfaceMaxPriorityQueue<T extends Comparable<T>>
-