Home  >  Article  >  Java  >  What is the difference between queue and stack in java

What is the difference between queue and stack in java

王林
王林Original
2020-05-15 11:21:444295browse

What is the difference between queue and stack in java

The difference between a stack and a queue is as follows:

1. The queue is first in, first out, and the stack is first in, last out;

2. Queues and stacks belong to the same The Java collection framework is implemented by the Collection interface, but the queue is implemented by the Queue interface, and the stack is implemented by the List interface;

(Video tutorial recommendation: java video)

3. A stack is a linear list that limits insertion and deletion operations to only one end of the table; a queue is a linear list that limits insertions to only one end of the table and deletion operations to the other end;

4. The stack only Data can be fetched from the head, which means that the first thing put in needs to traverse the entire stack before it can be taken out. When traversing the data, temporary space must be opened for the data to maintain the consistency of the data before and after traversal; the queue is based on address The pointer is traversed, and it can be traversed from the beginning or the end without opening up a temporary space, which is much faster;

5. Common stack application scenarios include solving bracket problems, expression conversion and evaluation, Function calls and recursive implementations, depth-first search traversal, etc.; common queue application scenarios include management of various resources in computer systems, message buffer management, breadth-first search traversal, etc.

Recommended tutorial: java entry program

The above is the detailed content of What is the difference between queue and stack in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn