当前位置:网站首页>Queue (stack)
Queue (stack)
2022-07-24 13:14:00 【No fish in Haikou】
java.util.Queue Queue interface
- Queue Inherited from Collection, So the queue itself is also a collection
- A queue can hold a set of elements , But the characteristic is that the access elements must follow the principle of first in, first out
- Common implementation classes :java.util.LinkedList
offer Method : Joining operation , The element is appended to the end of the queue
poll Method : Out of line operation , After getting the first element of the queue, the element is deleted from the queue
peek Method : Reference the team leader element , After obtaining, the element is still in the queue
Queue<String> queue = new LinkedList<>();
queue.offer("one");
queue.offer("two");
queue.offer("three");
System.out.println(queue); //[one, two, three]
String str = queue.poll();
System.out.println(str); //one
System.out.println(queue); // [two, three]
str =queue.peek();
System.out.println(str); //two
System.out.println(queue); // [two, three]
The stack structure
- The stack can hold a set of elements , However, the access elements must follow the principle of "first in, last out". Usually, the stack queue structure is used to complete the forward " back off " Use of such functions
- Deque If the double ended queue is queued from the same side, the stack structure is realized , therefore Deque Also known as stack, it provides a classic way to get in and out of the stack :push,pop
push: The stack operation element will be appended to the top of the stack
pop: The stack, , After getting the first element of the stack, the element is deleted from the stack
Deque<String> stack = new LinkedList<>();
stack.push("one");
stack.push("two");
stack.push("three");
stack.push("four");
System.out.println(stack);
String str = stack.pop();
System.out.println(str); //[four, three, two, one]
System.out.println(stack); //[three, two, one]
Two terminal queue interface :java.util.Deque
- Deque Inherited from Queue. The feature is that both ends of the queue can be queued
- Common implementation classes :java.util.LinkedList
Deque<String>deque = new LinkedList<>();
deque.offer("one");
deque.offer("two");
deque.offer("three");
deque.offer("four");
System.out.println(deque);
deque.offerFirst("five"); // Join the team from the head of the team
deque.offerLast("six"); // Join the team from the end of the team , And offer Agreement
String str = deque.poll(); // Go out from the head of the team
str = deque.pollFirst(); // Go out from the head of the team
str = deque.pollLast(); // Leave the team from the end of the team
边栏推荐
- How to draw Bezier curve and spline curve?
- SSM online campus album management platform
- About packaging objects
- Inversion of array (output in reverse order) (define an array and assign a value to output the array in reverse order)
- [datasheet] interpretation of phy lan8720 network chip
- 35.8. string conversion integer (ATOI)
- How to quickly learn Embedded
- Deep and shallow copies of objects, extends
- SSM online rental and sales platform multi city version
- sql的where+or的用法丢失条件
猜你喜欢

Wang Ping, co-founder of Denglin Technology: Innovation + self research "dual core" drive, gpu+ enabling AI takes root | quantum bit · viewpoint sharing review

25. Middle order traversal of binary tree

Analysis of ISP one click download principle in stm32

The second batch of projects of Shenzhen Metro Line 12 passed the acceptance and is expected to be put into trial operation on July 28

About the concept of thread (1)

Inversion of array (output in reverse order) (define an array and assign a value to output the array in reverse order)

The price of domestic flagship mobile phones is nearly 6000, but they can't even beat iphone12. It's clear who users choose

Custom scroll bar

汉字风格迁移篇---无监督排版传输

Implementation of dynamic columns in EAS BOS doc list
随机推荐
基于matlab的语音处理
现代数据架构选型:Data Fabric、Data Mesh
深圳地铁12号线第二批工程验收通过 预计7月28日试运行
Atcoder beginer contest 261e / / bitwise thinking + DP
English grammar_ Indefinite pronouns - Overview
An example of how to save various data types by using esp32 EEPROM library functions under Arduino framework
SSM online examination system including documents
SSM在线校园相册管理平台
ESP32ADC
Redis(13)----浅谈Redis的主从复制
20201127 use markdown to draw UML diagrams, graphviz installation experience hematemesis finishing
About thread (3) thread synchronization
About the concept of thread (1)
leetcode第 302 场周赛复盘
[datasheet] interpretation of cs5480 data book of metering chip
SSM hospital inpatient management system
Vscode configuration user code snippet (including deletion method)
Wang Ping, co-founder of Denglin Technology: Innovation + self research "dual core" drive, gpu+ enabling AI takes root | quantum bit · viewpoint sharing review
Handler learning
EAS approval process related table