#include <iostream>
using namespace std;

const int maxQsize = 100;

template < typename T > class Queue {
  T q[maxQsize]; // this array holds the queue
  int size; // the maximun number of elements that the queue can store
  int putloc, getloc; // the put and get indices
public:

  // Construct a queue of a specific length.
  Queue(int len) {
    // Queue must be less than max and positive.
    if(len > maxQsize) len = maxQsize;
    else if(len <= 0) len = 1;

    size = len;
    putloc = getloc = 0;
  }

  // Put a 'T' into the queue.
  void put( const T& v ) {
    if(putloc == size) {
      cout << " -- Queue is full.\n";
      return;
    }

    putloc++;
    q[putloc] = v ;
  }

  // Get a 'T' from the queue.
  T get() {
    if(getloc == putloc) {
      cout << " -- Queue is empty.\n";
      return 0;
    }

    getloc++;
    return q[getloc];
  }

  bool empty() const { return getloc == putloc ; }
};

// Demonstrate the Queue class.
int main() {

  Queue<char> charq (100);
  const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  for( char c : alphabet ) charq.put(c) ;
  while( !charq.empty() ) cout << charq.get() ;
  std::cout << '\n' ;

  Queue<int> intQ(4);
  for( int i = 0 ; i < 6 ; ++i ) intQ.put(i) ;
  while( !intQ.empty() ) cout << intQ.get() << ' ' ;
  std::cout << '\n' ;

  Queue<double> dblQ(50);
  for( int i = 0 ; i < 10 ; ++i ) dblQ.put( i * 1.57 ) ;
  while( !dblQ.empty() ) cout << dblQ.get() << ' ' ;
  std::cout << '\n' ;
}
