手写队列,栈(STL党必备)

//作为忠实的STL党,队列和栈经常会影响速度,所以可通过手写struct来代替STL
其实也不会卡的很厉害,尽量写和以前一样的防止出错

queue

struct queue{
	const int maxn = 100000 + 100;
    int l = 0,r = 0,a[maxn];
    void push(int x){
        a[++r] = x;
    }
    int front(){
        return a[l];
    }
    void pop(){
        l++;
    }
    int empty(){
        return l > r ? 1 : 0;
    }
}q;

stack

struct stack{
	const int maxn = 100000 + 100;
    int a[maxn], l = 0;
    void push(int x){
        a[++l] = x;
    }
    int front(){
        return a[l];
    }
    void pop(){
        l--;
    }
    int empty(){
        return l >= 0 ? 1 : 0;
    }
}q;
posted @ 2017-11-09 08:10  Taunt  阅读(175)  评论(0)    收藏  举报