zoukankan      html  css  js  c++  java
  • deque in Python

    Python中的deque(Doubly Ended Queue)是使用collections模块实现的。

    在我们需要从容器的两端更快地执行append和pop操作的情况下,与列表相比,使用双端队列更可取,因为与O(n)时间复杂度的列表相比,双端队列为append和pop操作提供了O(1)时间复杂度。

    • append() :- This function is used to insert the value in its argument to the right end of deque.
    • appendleft() :- This function is used to insert the value in its argument to the left end of deque.
    • pop() :- This function is used to delete an argument from the right end of deque.
    • popleft() :- This function is used to delete an argument from the left end of deque. 
    • index(ele, beg, end) :- This function returns the first index of the value mentioned in arguments, starting searching from beg till end index.
    • insert(i, a) :- This function inserts the value mentioned in arguments(a) at index(i) specified in arguments.
    • remove() :- This function removes the first occurrence of value mentioned in arguments. 
    • count() :- This function counts the number of occurrences of value mentioned in arguments. 
    • extend(iterable) :- This function is used to add multiple values at the right end of deque. The argument passed is an iterable.
    • extendleft(iterable) :- This function is used to add multiple values at the left end of deque. The argument passed is an iterable. Order is reversed as a result of left appends.
    • reverse() :- This function is used to reverse order of deque elements.
    • rotate() :- This function rotates the deque by the number specified in arguments. If the number specified is negative, rotation occurs to left. Else rotation is to right.  
    • in:- This function is to find the element is in the deque or not
    • copy:- This function is to copy a deque

      

     
  • 相关阅读:
    [NOI2019]回家路线(最短路,斜率优化)
    LOJ6686 Stupid GCD(数论,欧拉函数,杜教筛)
    Codeforces Global Round 4 题解
    CF908G New Year and Original Order(DP,数位 DP)
    [BJOI2019]光线(DP)
    CF1194F Crossword Expert(数论,组合数学)
    SPOJ31428 FIBONOMIAL(斐波那契数列)
    Codeforces Round 573 (Div.1) 题解
    [THUPC2018]弗雷兹的玩具商店(线段树,背包)
    数学基础
  • 原文地址:https://www.cnblogs.com/xxxsans/p/14344002.html
Copyright © 2011-2022 走看看