#include<iostream> template <class T> class Queue { private: T rear; T front; int maxSize; T* head; public: Queue(int size):rear(0),front(0),maxSize(size) { head = new T(size); if(!head) std::cout << "memoryAllocationError!" << std::endl; } ~Queue() { maxSize = 0; delete[] head; } bool IsEmpty() { return front == rear; } bool IsFull() { return rear - front == maxSize; } void inQueue(T item) { if(IsFull()) std::cout << "Queue is full!" << std::endl; *(head + rear) = item; rear ++; } T outQueue() { if(IsEmpty()) std::cout << "Queue is empty!" << std::endl; T item = *(head + front); front ++; return item; } void Destroy() { ~Queue(); } };
原文链接: https://www.cnblogs.com/VortexPiggy/archive/2012/05/06/2471816.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/49531
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!