天天看点

用List模拟实现STL下的queue队列

queue.h

template <class T>
class Queue
{
    typedef T value_type;
    typedef int size_type;
public:
    bool empty()const
    {
        return q.Empty();
    }
    value_type& back()
    {
        return q.Back();
    }
    const value_type& back()const
    {
        return q.Back();
    }
    value_type& front()
    {
        if (empty())
        {
            cout<<"queue is empty"<<endl;
            return ;
        }
        return q.Front();
    }
    const value_type& front()const
    {
        return q.Front();
    }
    void pop()
    {
        if (empty())
        {
            cout<<"queue is empty"<<endl;
            return ;
        }
        q.PopFront();
    }
    void push(const T& x)
    {
        q.PushBack(x);
    }
    size_type size()const
    {
        return q.Size();
    }
private:
    List<T> q;
};
           

test.c

#include "queue.h"
int main()
{
    Queue <int>q1;
    q1.push();
    q1.pop();
    q1.push();
    int a = q1.size();
    return ;
}