• 数据结构总结(UPDATING......)


    目标:

    1.栈........√

    2.队列......√

    3.堆.........×

    4.并查集...×

    栈:

     1 #define MAXN 65536
     2 struct stack{
     3     int sz[MAXN],now;
     4     stack()
     5     {
     6         now=0;
     7     }
     8     ~stack()
     9     {
    10         delete []sz;
    11     }
    12     void push(int x)
    13     {
    14         if(!full())
    15         sz[++now]=x;
    16     }
    17     int pop()
    18     {
    19         if(!empty())
    20         return sz[now--];
    21     }
    22     bool empty()
    23     {
    24         return now==0;
    25     }
    26     bool full()
    27     {
    28         return now==MAXN-1;
    29     }
    30     int top()
    31     {
    32         return sz[now];
    33     }
    34 };

    队列:

    #define MAXN 10000
    struct queue{
        int sz[MAXN];
        int head,tail;
        queue()
        {
            head=0;
            tail=0;
        }
        ~queue()
        {
            head=0;
            tail=0;
            delete []sz;
        }
        int front()
        {
            if(!empty())
            return sz[head];
        }
        bool empty()
        {
            return (head>=0&&tail>=0&&head==tail||head>tail);
        }
        bool full()
        {
            return tail>=MAXN;
        }
        int push(int x)
        {
            if(!full())
            sz[tail++]=x;
        }
        void pop()
        {
            if(!empty())
                ++head;
        }
    }
    队列

    并查集:

    #define maxn 10000
    struct UnionFindSet
    {
        int x,y,v;
        int fat[maxn];
        UnionFindSet()
        {
            for(int i=0;i<maxn;i++)
                fat[i]=i;
            x=y=v=0;
        }
        inline int father(int x)
        {
            if(fat[x]!=x)
                fat[x]=father(fat[x]);
            return fat[x];
        }
        inline void unionn(int x,int y)
        {
            int fa=father(x);
            int fb=father(y);
            if(fa!=fb)
                fat[fa]=fb;
        }
    };
    并查集
  • 相关阅读:
    HDU 4389 X mod f(x)
    SRM 400(1-250pt, 1-500pt)
    FZU 2113 Jason的特殊爱好
    POJ 3208 Apocalypse Someday
    HDU 4734 F(x)
    HDU 3555 Bomb
    HDU 2089 不要62
    poj2488(A Knight's Journey)
    poj3267(The Cow Lexicon)
    poj2513(Colored Sticks)
  • 原文地址:https://www.cnblogs.com/TheRoadToAu/p/6711048.html
Copyright © 2020-2023  润新知