内容简介:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yysyangyangyangshan/article/details/84981203
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yysyangyangyangshan/article/details/84981203
双端队列可以从队列的两端加入和删除元素。比如,在需要按照元素增加的顺序来移除元素时非常有用。
看下面的使用,
先产生一个双端队列。
from collections import deque q = deque(range(5)); print(q) 输出 deque([0, 1, 2, 3, 4])
q.append(99) q.appendleft(999) print(q) 输出 deque([999, 0, 1, 2, 3, 4, 99])
前后增加了999和99
print(q.pop()) print(q.popleft()) 输出 99 999
弹出前后的元素。
rotate用于旋转。将元素左移或者右移,使头尾相连。 q.rotate(3) print(q) 输出 deque([2, 3, 4, 0, 1])
如上为左移三位。
q.rotate(-1) print(q) 输出 deque([3, 4, 0, 1, 2])
这里是右移1位。
工程文件下载: https://download.csdn.net/download/yysyangyangyangshan/10846771
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
C++ Concurrency in Action
Anthony Williams / Manning Publications / 2012-2-28 / USD 69.99
HIGHLIGHT C++ Concurrency in Action is the first book to market to show how to take advantage of the new C++ Standard and how to write robust multi-threaded applications in C++. DESCRIPTION With ......一起来看看 《C++ Concurrency in Action》 这本书的介绍吧!