首页 > 代码库 > 数据结构总结(UPDATING......)

数据结构总结(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;
    }
}
队列

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