zoukankan      html  css  js  c++  java
  • c++ allocator,deque,stack用法

    参考cpp reference网站

    1,std::allocator

    template<class T> class allocator;

    Allocators are classes that define memory models to be used by some parts of the Standard Library, and most specifically, by STL containers.2,

    2,std::deque

    template<class T,class Allocator=allocator<T>>deque;

    std::deque (double-ended queue) is an indexed sequence container that allows fast insertion and deletion at both its beginning and its end. In addition, insertion and deletion at either end of a deque never invalidates pointers or references to the rest of the elements.

    As opposed to std::vector, the elements of a deque are not stored contiguously: typical implementations use a sequence of individually allocated fixed-size arrays, with additional bookkeeping, which means indexed access to deque must perform two pointer dereferences, compared to vector's indexed access which performs only one.

    The storage of a deque is automatically expanded and contracted as needed. Expansion of a deque is cheaper than the expansion of a std::vector because it does not involve copying of the existing elements to a new memory location. On the other hand, deques typically have large minimal memory cost;

    The complexity (efficiency) of common operations on deques is as follows:

        Random access - constant O(1)
        Insertion or removal of elements at the end or beginning - constant O(1)
        Insertion or removal of elements - linear O(n)

    3,std::stack

    template<class T,class Container = deque<T>>stack;

    LIFO stack

    Stacks are a type of container adaptor, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container.

    stacks are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed/popped from the "back" of the specific container, which is known as the top of the stack.

    The underlying container may be any of the standard container class templates or some other specifically designed container class. The container shall support the following operations:

  • 相关阅读:
    Windows10打印mumu模拟器日志
    简析快速排序
    数字转换为W,K,结尾,并可指定长度(仅供参考,个人测试使用。)
    简析选择排序
    简析冒泡排序
    NX二次开发 工程图创建孔表功能
    NX二次开发 建模座标和工程图座标映射
    NXOpen绝对座标值转为WCS座标值
    NX二次开发 结合包容盒快速创建WCS
    NX二次开发 数值转NXString字符
  • 原文地址:https://www.cnblogs.com/CreatorKou/p/8653940.html
Copyright © 2011-2022 走看看