当前位置:网站首页>Sorting out knowledge points of queue (single queue) and deque (double ended queue)
Sorting out knowledge points of queue (single queue) and deque (double ended queue)
2022-07-18 07:42:00 【Rong, who has to learn every day】
1、Queue( One way queue )
1.1 Definition
A common queue is FIFO( fifo ) queue , You can delete the front end (peek/pop from front), Back end add (push to back) The function of .
1.2 Realization ( You can use arrays - Sequential queue , You can also use a linked list - Chain queues )
A subinterface :BlockingQueue
- Java The single queue in is realized by linked list ;
- hinder Deque( deque ) Inherited Queue, It's the point , It is also a good thing .
- Queue Itself is an interface , Inherited Collection aggregate ;
- There are basic queue abstraction methods , Three types of , Insert elements at the end of the team , Team leader takes out elements , And delete the team head element ;
Method : Throw an exception / Return default (false / null)
Additive elements :add / offer
Delete :remove / poll
lookup :element / peek

2、Deque( deque )
1.1 Definition
deque , seeing the name of a thing one thinks of its function , It's not just FIFO( fifo ), You can also use LIFO (LIFO), There are also priority queues ...
1.2 Realization
deque (Deque) Inherited one-way queue (Queue), It also inherits all the abstract methods , So it also includes the method of adding, deleting and checking the basic queue .
Implementation class :LinkedList、ArrayDeque、ConcurrentLinkedDeque、LinkedBlockingDeque



Be careful :ArrayDeque( The bottom layer is a circular array ) and LinkedList( The bottom layer is a two-way circular list )
- Take up memory : Only data needs to be stored in the array , The bidirectional linked list also needs to store the addresses of the previous node and the next node , Therefore, the memory consumption is large .
- efficiency : For inquiry , Arrays naturally have advantages over linked lists , For addition and deletion , Only the header of the queue is deleted , Tail insertion ,ArrayDeque Just move the head or tail variable forward or backward by one bit , and LinkedList You also need to connect pointers , therefore ArrayDeque Is more efficient than LinkedList high .
- Null value :ArrayDeque Inserting... Is not allowed null,LinkedList Allow to insert null( But it's best not to ).
- Security : Both are thread unsafe .

1.3 Method
Deque The additional implementation methods are as follows :( Both the beginning and the end can be added, deleted and checked )
Deque Can be viewed as Queue Use , First in first out queue .
Queue Can be viewed as Stack Use .
Deque There is also an additional method in to delete the first or last matched element .
boolean removeFirstOccurrence(Object o);
boolean removeLastOccurrence(Object o);
reference :
1、Queue、Deque、LinkedList、ArrayDeque Relationship and method
2、 In depth understanding of Java Gather them together —Deque
3、 Why? java It is not recommended to use vector
4、 Analyze in simple terms ArrayDeque
边栏推荐
- Openharmony module II parsing of header files under interfaces (9)
- [basic use of oscilloscope] and [introduction to the meaning of each key on the oscilloscope key panel]
- CAS与AQS简单理解
- Firewall ha configuration
- 云上数字创新,如何塑造一座城市的幸福感?
- 【英雄哥七月集训】第 15天:深度优先搜索
- OpenHarmony模块二下文件samgr_server解析(2)
- Openharmony related knowledge learning
- Queue(单项队列)和Deque(双端队列)的知识点整理
- Detailed explanation of time complexity and space complexity
猜你喜欢

抽丝剥茧C语言(高阶)静态通讯录

美团一面面经及详细答案

(Dell Lingyue 7572) after the laptop expands the display, the laptop has no sound

客户端那些事儿(2)

mysql中出现Unit mysql.service could not be found 的解决方法

聊聊程序员的简历应该怎么写(帮修改简历)

Those things on the server side

Amd ryzen 5 7600x 6 core and 4.4ghz'zen 4 'CPU appear in the running sub database

Unit MySQL appears in MySQL Solution of service could not be found

Pytorch中torch.sort()和torch.argsort()函数解析
随机推荐
实现一下几个简单的loader
LAN attack and network device security configuration
Pytorch中torch.nonzero()函数解析
如何将面向Oracle开发的应用所使用到的复杂的SQL语句,迁移至基于PolarDB for Pos
[brother hero July training] day 15: depth first search
2022中国移动创客马拉松大赛物联网专题赛开赛啦
Redhat7.9 configure Yum source
2022 China mobile maker marathon Internet of things special competition kicks off
李沐动手学深度学习V2-目标检测数据集
Why can MySQL temporary tables have duplicate names?
AB website stress test
根据经纬度查询距离并按距离进行排序
Queue(单项队列)和Deque(双端队列)的知识点整理
Amd ryzen 5 7600x 6 core and 4.4ghz'zen 4 'CPU appear in the running sub database
How to make Sitemaps website map
来自JRockit的礼物:JMC虚拟机诊断工具
MODBUS-RS485布线的8条准则
英特尔发布开源AI参考套件
缓存穿透、缓存雪崩、缓存击穿?
How to migrate the complex SQL statements used by applications developed for Oracle to polardb for POS