Queuedemo/*** Presentation of queue queues * knowledge points: Queues are a common data organization that follows the principle of FIFO * The queue can be viewed as a special linear table, and the queue restricts access to the linear table: * You
This section provides some other ways to use deque . Provides a feature similar to the command tail in UNIX that displays a text at the end of a file:def tail (filename, n=10):' returns the last n lines of text ' of a filewith open (filename) as
Dual-ended queues:
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)
Returns the index IDX refers
Although previously written a deque, but that belongs to C and C + + mixed products, recently learned C + + templates, so wrote a C + + version, and the first attempt to use trait technology.Had already written a good article, Post lost, good
The first two posts have introduced the vectors and list of the two containers, we found that they each have their own advantages and disadvantages, vector in memory continuous storage, support random access, but the efficiency of the search and
One of the secrets of Vector's excellent efficiency is the allocation of more memory than the element it accommodates.Deque compared to vectors, the functional differences are as follows:· Both ends are able to quickly insert elements and remove
Vectors and lists and deque differ in their respective pros and cons: vector: Advantages: Random access, that is, [] operations and vector.at () dynamic operations, push_back () and Pop_back () automatically adjust memory, save space Disadvantage:
1. Container element typeMost data types in C + + can be the element type of a container. The container element type must satisfy two conditions: assignment and copy operations are supported.So no element is a container of the reference type, and
1 vector
Vector is equivalent to an arrayAllocate a continuous memory space in the memory for storage. Storage with no vector size specified is supported. During internal implementation of STL, a very large memory space is allocated for storage,
STL provides three basic containers: vector, list, And deque.
The vector and built-in arrays are similar. They have a continuous memory space and the starting address remains unchanged.
It supports instant access, that is, the [] Operator. However,
Double-end Queue (deque container class): # include is similar to vector. It supports random access and fast insertion and deletion. the operation on a specific position in the container takes linear time. Unlike vector, deque also supports data
Transferred from: http://blog.csdn.net/truexf/article/details/17303263First, VectorVector uses a contiguous memory to store its elements, adding elements to the vector, if the capacity is insufficient, the vector will re-malloc a larger chunk of
Similarities:
1. Ordered container
2. Dynamic one-dimensional array
3. the time complexity of insert and delete operations in the middle is O (n );
4. Quick and Random Access to elements
Differences:
1. Vector supports push_back and
Stack stack, no iterator, supports the push () method. After going forward, go first, top () returns the top element, and pop () removes the top element.
Deque dual-end queue, supports iterator, has push_back () method, and is similar to vector, has
Basic requirements: 1) Basic differences with Vecctor Vectors are added and removed at the tail,Deque added and removed at the tail, added and removed in the header.2) Basic knowledge: 3) Deque of the structure of the form:4) Basic operation
1) Dequeue can quickly insert or delete both at the front or the end. However, vector can only quickly insert or delete at the end.2) Memory allocation is different. A vector always occupies a contigious region of memory. If a vector goes too large,
The example in this article describes how Java uses deque to implement stacks. Share to everyone for your reference. as follows:
Import Java.util.ArrayDeque;
Import Java.util.Deque;
public class Integerstack {private deque data = new
I can't remember peek poll. A large pile of operations, record the difference deque interface
AddFirst AddLast
Offerfirst Offerlast
Removefirst Removelast
Pollfirst Polllast
GetFirst GetLast
Peekfirst Peeklast
(Push pop stack operation is
Sequential containers::(vectors and lists and deque)The erase iterator not only invalidates all iterators that point to the deleted element, but also invalidates all iterators after the deleted element, so erase (iter++) cannot be used, but the
C + + Handbook of DequeOwning header file Common operations:Back () returns the trailing element;Front () returns the head element;Push_back () tail insertion element;POP_BAKC () tail delete element;Push_front () head insertion element;Pop_front ()
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.