// L-17 MCS 360 Fri 1 Oct 2010 : mcs360_circular_fixed_buffer.tc /* Implements the operations with prototypes in the circular buffer. */ #include "mcs360_circular_fixed_buffer.h" #include namespace mcs360_circular_fixed_buffer { template Queue::Queue( int c ) { capacity = c; data = new T[c]; current = -1; back = -1; number = 0; } template void Queue::push( T item ) { // std::cout << "pushing " << item << std::endl; this->back = (this->back + 1) % this->capacity; this->data[this->back] = item; this->number = this->number + 1; if(this->current < 0) this->current = 0; // std::cout << "number after push " << this->number << std::endl; } template bool Queue::empty() { return (this->number == 0); } template T Queue::front() { // std::cout << "front current = " << this->current << std::endl; return data[this->current]; } template void Queue::pop() { this->current = (this->current + 1) % this->capacity; this->number = this->number - 1; } }