Sicily 2302. Queue Implementation Using a Circular

来源:互联网 发布:职业调查报告网络调研 编辑:程序博客网 时间:2024/06/05 19:33

2302. Queue Implementation Using a Circular Array

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB , Framework Judge

Description

template <typename T> class Queue {
public:
     Queue();   // construct an empty queue
      ~Queue()  // destructor
      Queue(const Queue &rhs);
      const Queue & operator(const Queue &rhs)
      bool empty()const;
      bool full()const;
      int size()const;
      bool push(const T &x);//enqueue
      bool pop();//dequeue
      const T & front()const;//returns a reference to the front element
private:
 //using a static array of size 100.   

};

 

Input

None

Output

None

Hint

Submit your implementation only.

Problem Source

ADTs: Implementations and Applications

// Problem#: 2302// Submission#: 3371367// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen Universitytemplate <typename T> class Queue {public:    Queue() {        counter = 0;    }    ~Queue() {        counter = 0;    }    Queue(const Queue &rhs) {        counter = rhs.size();        for (int i = 0; i < counter; i++) a[i] = rhs.a[i];    }    const Queue & operator=(const Queue &rhs) {        counter = rhs.size();        for (int i = 0; i < counter; i++) a[i] = rhs.a[i];    }    bool empty() const {        return counter == 0;    }    bool full() const {        return counter == 100;    }    int size() const {        return counter;    }    bool push(const T &x) {        if (counter < 100) {            a[counter++] = x;            return true;        } else return false;    }    bool pop() {        if (counter) {            for (int i = 0; i < counter - 1; i++) a[i] = a[i + 1];            counter--;            return true;        } else return false;    }    const T & front() const {        if (counter) return a[0];    }private:    T a[105];    int counter;};                                 


0 0
原创粉丝点击