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

来源:互联网 发布:mac系统剪切文件 编辑:程序博客网 时间:2024/05/22 13:29

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 0;        }        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(7);    q1.pop();    q1.push(8);    int a = q1.size();    return 0;}
0 0
原创粉丝点击