C + + in the STL is still more useful, especially in the implementation of scientific research algorithms, but also useful, but not how the system has been studied, so recently looked for a book, Ye Zhijun the "C + + STL development Technology Guidance", science, the nature of a book, written relatively shallow [hehe, do not spray ]。 Most of the content below is excerpted from the book.Deque double-ended queue container (double-ended queue), can be inserted in the tail, head, delete elements, th
operations at both ends: push_back, push_front, pop_back, pop_front, etc, in addition, the operation efficiency on both ends is similar to that on list.Therefore, in actual use, how to select one of the three containers should be determined according to your needs. Generally, the following principles should be followed:1. If you need efficient instant access without worrying about the efficiency of insertion and deletion, use the Vector2. If you need to insert and delete a large number of objec
#2: Deque also provides append and Pop methods that can be executed at the same speed at both ends of the sequence#例子2: Implement FIFO using Deque, as follows:From collections Import DequeImport Profile,statImport SysQeque=deque ()def add1 (data):Qeque.append (data)Def add2 ():Qeque.pop ()big_n=100000@profile (' deque
Reference to:http://www.infoq.com/cn/articles/android-accessibility-installing?utm_campaign=infoq_content Utm_source=infoqutm_medium=feedutm_term=globalFor domestic Android devices, automatic batch installation/update of applications has always been a pain point, before the third-party store typically requires device root and then calls the system's Packagemanagerservice command line for background installation. Recently, pea pods have been the first
Deque is an abbreviation for double-ended queue, similar to list, but provides an action to insert and delete at both ends.
Appendleft inserts to the left of the list
Popleft the value on the left side of the pop-up list
Extendleft extension on the left
For example:
Queue = Deque ()
# append values to wait for processing
queue.appendleft ("a")
Queue.appendleft ("second"
Queue.appen
Create a Deque sequence:
From collections import dequed = deque ()
Deque provides a list-like operation method:
D = deque () d. append ('1') d. append ('2') d. append ('3') len (d) d [0] d [-1]
Output result:
3 '1' 3'
Both ENDS Use pop:
D = deque ('000000') len (d) d.
Back to General bookIn the original section: http://www.cplusplus.com/reference/deque/deque/1. std::d equeTemplate Dual-ended queuesDeque (pronounced like "deck") is a special abbreviation for Double-ended-queUE. Deque is a dynamic-length sequence container that can be extended to either end or shortened from either end.Different libraries have different implemen
Snow", 18, 175]) # Access Print ( Info._asdict ()) Defaultdictis a dict extension class that accesses the dictionary key if it is not, automatically sets the default value and adds the dictionaryinfo = dict () name = Info.setdefault (' name ', "North Gate Blown Snow") print (name, info) from collections import defaultdict# default value must be an iterative object info = Defaultdict (lambda: "North gate blowing Snow") name = info[' name ']print (name, info)
Deque is an abbreviation for the double-ended queue, similar to list, but provides an operation to insert and delete at both ends.
Appendleft inserts to the left of the list
Popleft the value to the left of the popup list
Extendleft extension on the left
For example:
Queue = Deque () # Append values to wait for Processingqueue.appendleft ("first") Queue.appendleft ("second") Queue.appendlef
#include
The deque bidirectional queue is a continuous linear space with two-way openings that efficiently insert and delete elements at both ends of the deque and are very similar to vectors on the interface
Function
Describe
C.assign (Beg,end)C.assign (N,elem)
Assigns the data in the [beg; end] Interval to C.Assigns a copy of n elem to C.
c.at (IDX)
Return
First, when considering the memory allocation and execution performance, it is better to use std: deque than std: vector.
Deque Overview
Deque and vector are both in the standard template library. deque is a dual-end queue, which is very similar to vector in the interface and can be directly replaced in many operations
/****************************************** ***** Deque:**************************************** ******* Random access is allowed. elements are inserted and deleted in the ** header and tail **. the time complexity is O (1)* Random Access container back insertion sequence front Insertion Sequence***************************************** **************************************** ***** Deque is more advantageo
In STL, the basic containers include string, vector, list, deque, set, and map.
Set and map are unordered storage elements. They can only be accessed through the interfaces provided by it;
Set: set, which is used to determine whether an element is in a group and is rarely used;Map: ing, which is equivalent to a dictionary. It maps a value to another value. If you want to create a dictionary, use it;The underlying layer uses a tree structure, most of w
); // delete all elements whose values are 11 in the linked list.
5. Reverse linked list
Lt. Reverse (); // reverse the order of elements in the linked list
6. Order (Ascending by default)
Lt. Sort ();
7. Delete adjacent duplicate elements
Lt. Unique (); // you must first sort it by Lt. Sort (). After sorting, the same element must be adjacent.
Deque usage
Deque also uses dynamic arrays, but the memory mana
Ordered container: vector, deque, list, vectordeque
1. Ordered containers: vector, deque, list
Containers share public interfaces. You only need to learn one type and use another type. Each container provides a set of different time and functions. Generally, you do not need to modify the code, order change type declaration, and each container type replaces another container type, the program performance can
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.