• 常见数据结构及基本用法


    1:stack(#include<stack>)

    size( ) :返回栈中元素个数

    top( ) :返回栈顶的元素

    pop( ) :从栈中取出并删除元素

    push(e) :向栈中添加元素e

    empty( ) :栈为空时返回true

    {

    手写栈

    int s[100005],tot=0;
    #define push(x) s[++tot]=x
    #define pop tot--
    #define size tot
    #define top s[tot]
     

    }

    2:vector(#include<vector>)

    push_back( ) :向量末尾插入元素

    pop_back( ) :向量末尾删除元素

    size( ) :获取向量中的元素个数

    empty( ):判断向量是否为空

    clear( ):清空向量中的元素

    a=b 将b向量复制到a向量中

    比较:保持 ==、!=、>、>=、<、<= 的惯有含义 ;

    如: a == b ; //a向量与b向量比较, 相等则返回1

    3 : (1)queue(#include<queue>)

    front():返回 queue 中第一个元素的引用

    back():返回 queue 中最后一个元素的引用

    push() : 向 queue 末尾插入一个元素

    pop():删除 queue 中的第一个元素

    size():返回 queue 中元素的个数

    empty():如果 queue 中没有元素的话,返回 true

    {

    (手写队列)

    int s[100005],fnt,end;
    #define push(x) s[++end]=x
    #define pop fnt++
    #define front s[fnt]
    #define size end-fnt+1
     

    }

     (2)priority_queue

    top(): 访问队头元素

    empty(): 队列是否为空

    size(): 返回队列内元素个数

    push(): 插入元素到队尾 (并排序)

    可自定义{

    默认从大到小;

    更改:

    friend bool operator <(use a,use b){

    return a.x>b.x;}

    }

     4:deque

     deq.size():容器大小

    max_size():容器最大容量

    deq.resize():更改容器大小

    empty():容器判空

    push_front():头部添加元素

    psuh_back():末尾添加元素

    pop_front():头部删除元素

    pop_back():末尾删除元素

    可下标访问但时间复杂度大

  • 相关阅读:
    Codeforces Round #544 (Div. 3) C. Balanced Team
    Codeforces Round #544 (Div. 3) B.Preparation for International Women's Day
    Codeforces Round #544 (Div. 3) A.Middle of the Contest
    HDU-2647-Reward
    2015.3.15
    USACO Section 5.1 Musical Themes(枚举)
    [STOI2014]舞伴(dp)
    USACO Section 5.1 Fencing the Cows(凸包)
    2015.3.10
    USACO Section 4.3 Street Race(图的连通性+枚举)
  • 原文地址:https://www.cnblogs.com/zyfltyyz/p/11712919.html
Copyright © 2020-2023  润新知