- queues are FIFO structures (first in, first out)
- they're an array of elements where you can only add to the end and remove from the beginning
- examples of real-world queues include people waiting in a checkout line
- queues are most often used in scheduling algorithms
- particularly in scheduling algorithms that deal with Poisson-distributed events
- methods that queues (should) implement
bool queue(E data)addsdatato the end of the arrayE enqueue()removes and returns the first element in the arrayE peek()returns the first element in the array without removing itbool isEmpty()tells whether the array has any elements in it (obviously)
LinkedListsare the best structure to use to implement queues- it's fast to add to the end of them
- and fast to remove from the beginning
- because of the head and tail nodes
ArrayListsare only fast to remove/add to the end (O(1))- any operation at the beginning of an
ArrayListwill be an O(n) operation
- any operation at the beginning of an