A FIFO data structure!
First In First Out
Queues exist everywhere! Think about the last time you waited in line....
How do we use them in programming?
class Queue {
constructor(){
this.first = null;
this.last = null;
this.size = 0;
}
}
class Node {
constructor(value){
this.value = value;
this.next = null;
}
}
A series of nodes!
10
2
22
7
last
first
size = 4
Adding to the beginning of the Queue!
Remember, queues are a FIFO data structure
Removing from the beginning of the Queue!
Remember, queues are a FIFO data structure
Insertion - O(1)
Removal - O(1)
Searching - O(N)
Access - O(N)