手写队列 栈

版权声明:https://blog.csdn.net/huashuimu2003 https://blog.csdn.net/huashuimu2003/article/details/84639116
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;
struct stack
{
    const int maxn = 100000 + 100;
    int a[maxn], top = 0;
    void push(int x)
	{
        a[++top] = x;
    }
    int front()
	{
        return a[top];
    }
    void pop()
	{
        --top;
    }
    int empty()
	{
        return top >= 0 ? 1 : 0;
    }
}s;

猜你喜欢

转载自blog.csdn.net/huashuimu2003/article/details/84639116