zoukankan      html  css  js  c++  java
  • 数据结构总结(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;
        }
    };
    并查集
  • 相关阅读:
    队列(queue)、优先队列(priority_queue)、双端队列(deque)
    20150720工作总结
    Spring使用远程服务之Hessian
    iBaits中SqlMapClientTemplate的使用
    java中常见的异常类
    java笔试面试中的坑
    java面试中常用的排序算法
    IBatis和Hibernate区别
    单例和多线程
    ThreadLocal
  • 原文地址:https://www.cnblogs.com/TheRoadToAu/p/6711048.html
Copyright © 2011-2022 走看看