V
V
vitya_brodov2021-03-02 12:18:48
Java
vitya_brodov, 2021-03-02 12:18:48

Why is Queue needed?

Hello!
I can't understand why Queue/Deque is needed.
1. How to use it?
2. When does it apply?
3. How often is it used in practice?

ps I will be glad if you show a good example (preferably in Java)
Thanks in advance for any answer!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
12rbah, 2021-03-02
@12rbah

on points 1,2,3 Try to drive your question into Google there for you, on request, they have already written an article on Habré. For you Java implementation https://gist.github.com/sschakraborty/d921d2051476...

O
Orkhan, 2021-03-02
Hasanly @azerphoenix

Good afternoon!
To begin with, it would be nice to understand terms such as: FIFO & LIFO
FIFO - first in - first out. "First in, first out." This is a good example of a queue. The customer who is first in line will be served.
LIFO - last in - first out. "Last in, first out." This is a clear example of how the stack works. Those. this is the reverse FIFO principle. The first client to be served is the one at the end of the queue (top of the stack).
Now, knowing what FIFO & LIFO is, it is worth noting that Queue (from the English queue) is an interface that is based on the FiFO principle.
The choice of jcf implementation depends on your goal, since each of the collections performs one or another operation in a different time. This is shown in the table below:
603e3b8cc408a641092521.png
Useful related link:
https://codenza.app/java-collections/
https://www.examclouds.com/ru/java/java-core-russi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question