Sicily 2302. Queue Implementation Using a Circular

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 University
template <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;
};                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值