Data Structures
Queue
To create a queue
Queue<object_type> queue = new LinkedList<>();to insert an element
queue.add(object);to see the head
queue.peek();to remove the head
object_type object = queue.poll();Stack
To create a stack
Stack<object_type> stack = new Stack<>();to insert an element
stack.push(object);to remove an element on top
object_type object = stack.pop();to see the top of the stack
object_type object = stack.peek();Heap
The PriorityQueue is based on the Priority Heap
// Priority Queue Min Type by deafault
PriorityQueue<object_type> heap = new PriorityQueue<>();
// Priority Queue Max Type use comparator
PriorityQueue<object_type> heap = new PriorityQueue<>(Collections.reverseOrder());to add an element
heap.add(o);to see the top of the queue
object_type o = heap.peek();to remove the top element
object_type o = heap.poll();to remove object o from the queue
object_type o = heap.remove(o);