Queues
In contrast to stack, queues operate on a FIFO (First In, First Out) basis. Therefore, the first item inserted into a queue will be the first item removed. It means that for queues, we can manipulate only the first item exclusively. The queue data structure behavior resembles the queue in real life.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/212d3d3e-af15-4df9-bb13-5cbbb8114954/queue%2Bpict.png)
Queue implementation
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/212d3d3e-af15-4df9-bb13-5cbbb8114954/queue.png)
Queue is also an abstract data type. As well as stack, queue also defines two basic operations, insertion and deletion, which are implemented in two basic methods:
enqueue()
- inserts an element into an end of a queue;dequeue()
- removes a first element from a queue.
The queue abstract data type can be implemented with the help of both the array or linked list data structure.
Basic operations time complexity
Method | Array Implementation | Doubly Linked List Implementation |
---|---|---|
enqueue() | O(1) | O(1) |
dequeue() | O(1) | O(1) |
Все було зрозуміло?
Зміст курсу
Algorithms and Data Structures Overview
Algorithms and Data Structures Overview
Queues
In contrast to stack, queues operate on a FIFO (First In, First Out) basis. Therefore, the first item inserted into a queue will be the first item removed. It means that for queues, we can manipulate only the first item exclusively. The queue data structure behavior resembles the queue in real life.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/212d3d3e-af15-4df9-bb13-5cbbb8114954/queue%2Bpict.png)
Queue implementation
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/212d3d3e-af15-4df9-bb13-5cbbb8114954/queue.png)
Queue is also an abstract data type. As well as stack, queue also defines two basic operations, insertion and deletion, which are implemented in two basic methods:
enqueue()
- inserts an element into an end of a queue;dequeue()
- removes a first element from a queue.
The queue abstract data type can be implemented with the help of both the array or linked list data structure.
Basic operations time complexity
Method | Array Implementation | Doubly Linked List Implementation |
---|---|---|
enqueue() | O(1) | O(1) |
dequeue() | O(1) | O(1) |
Все було зрозуміло?