Package org.insa.graphs.algorithm.utils
Class BinarySearchTree<E extends java.lang.Comparable<E>>
- java.lang.Object
-
- org.insa.graphs.algorithm.utils.BinarySearchTree<E>
-
- All Implemented Interfaces:
PriorityQueue<E>
public class BinarySearchTree<E extends java.lang.Comparable<E>> extends java.lang.Object implements PriorityQueue<E>
-
-
Constructor Summary
Constructors Constructor Description BinarySearchTree()Create a new empty binary search tree.BinarySearchTree(BinarySearchTree<E> bst)Create a copy of the given binary search tree.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EdeleteMin()Remove and return the smallest item from the priority queue.EfindMin()Retrieve (but not remove) the smallest item in the queue.voidinsert(E x)Insert the given element into the queue.booleanisEmpty()Check if the priority queue is empty.voidremove(E x)Remove the given element from the priority queue.intsize()Get the number of elements in this queue.
-
-
-
Constructor Detail
-
BinarySearchTree
public BinarySearchTree()
Create a new empty binary search tree.
-
BinarySearchTree
public BinarySearchTree(BinarySearchTree<E> bst)
Create a copy of the given binary search tree.- Parameters:
bst- Binary search tree to copy.
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Description copied from interface:PriorityQueueCheck if the priority queue is empty.Complexity: O(1)
- Specified by:
isEmptyin interfacePriorityQueue<E extends java.lang.Comparable<E>>- Returns:
- true if the queue is empty, false otherwise.
-
size
public int size()
Description copied from interface:PriorityQueueGet the number of elements in this queue.Complexity: O(1)
- Specified by:
sizein interfacePriorityQueue<E extends java.lang.Comparable<E>>- Returns:
- Current size (number of elements) of this queue.
-
insert
public void insert(E x)
Description copied from interface:PriorityQueueInsert the given element into the queue.Complexity: O(log n)
- Specified by:
insertin interfacePriorityQueue<E extends java.lang.Comparable<E>>- Parameters:
x- Item to insert.
-
remove
public void remove(E x) throws ElementNotFoundException
Description copied from interface:PriorityQueueRemove the given element from the priority queue.Complexity: O(log n)
- Specified by:
removein interfacePriorityQueue<E extends java.lang.Comparable<E>>- Parameters:
x- Item to remove.- Throws:
ElementNotFoundException
-
findMin
public E findMin() throws EmptyPriorityQueueException
Description copied from interface:PriorityQueueRetrieve (but not remove) the smallest item in the queue.Complexity: O(1)
- Specified by:
findMinin interfacePriorityQueue<E extends java.lang.Comparable<E>>- Returns:
- The smallest item in the queue.
- Throws:
EmptyPriorityQueueException- if this queue is empty.
-
deleteMin
public E deleteMin() throws EmptyPriorityQueueException
Description copied from interface:PriorityQueueRemove and return the smallest item from the priority queue.Complexity: O(log n)
- Specified by:
deleteMinin interfacePriorityQueue<E extends java.lang.Comparable<E>>- Returns:
- The smallest item in the queue.
- Throws:
EmptyPriorityQueueException- if this queue is empty.
-
-