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 void
add(PNode<T> p)
void
add(T x)
Insert into the priority queue, and return a PNode that can be used by decreaseKey.T
deleteMax()
Remove the biggest item from the priority queue.T
findMax()
Find the biggest item in the priority queue.ArrayList<T>
getAll()
void
increaseKey(PNode<T> p, T newVal)
Change the value of the item stored in the pairing heap.boolean
isEmpty()
Test if the priority queue is logically empty.static void
main(String[] args)
void
makeEmpty()
Make the priority queue logically empty.void
merge(MaxPriorityQueue<T> b)
int
size()
String
toString()
-
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:
add
in interfaceMaxPriorityQueue<T extends Comparable<T>>
- Parameters:
x
- the item to insert.
-
add
-
findMax
Find the biggest item in the priority queue.- Specified by:
findMax
in interfaceMaxPriorityQueue<T extends Comparable<T>>
- Returns:
- the biggest item, or null if empty.
-
deleteMax
Remove the biggest item from the priority queue.- Specified by:
deleteMax
in 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:
getAll
in interfaceMaxPriorityQueue<T extends Comparable<T>>
-
toString
-
main
-
merge
- Specified by:
merge
in interfaceMaxPriorityQueue<T extends Comparable<T>>
-
size
public int size()- Specified by:
size
in interfaceMaxPriorityQueue<T extends Comparable<T>>
-