Queues

What are queues?

Queues are, like their namesake, a line. They follow the First In First Out (FIFO) principle, where everything goes in the back of the queue and everything comes out the front of the queue. 

A java queue has an enqueue function that adds data to the end of the queue, a dequeue function that removes and returns the first element of the queue, a size function that returns the number of items in the queue, a front/peek function that returns the data stored in the front of the list, an isEmpty function to check if it has items, and a toString function that converts the data into a printable string. 

What are deques?

Deques are similar to queues except you can add and remove data from either end of the data  structure. You can also look at the values on either end (peek front & back). 

The main functions are the same as queues except deques have add front, add rear, remove front, and remove rear instead of enqueue and dequeue.

What are priority queues?

Priority queues are structures that assign each value an associated priority value. The queue will then be ordered according to that value. Binary heaps are oftentimes used to implement priority queues. 

A java priority queue has an insert function that inserts a new element into the priority queue with a specified priority value, extract minimum and maximum function to pop the last or the first element in the queue, a peek min and peek max, a function to change the priority value of an existing element, and the standard Java isEmpty, toString, and size.

Full course
Next Lesson