#include "stdafx.h"
#include <iostream>
using namespace std;
#define SIZE 100
template <class Qtype>
class q_type {
Qtype queue[SIZE]; // содержит очередь
int head, tail; // индекс вершины и хвоста очереди
public:
q_type():head(0), tail(0)
{}
void q(Qtype num); // помещает в объект в очередь
Qtype deq(); // извлекает объект из очереди
void print();
};
// Помещение значения в очередь
template <class Qtype>
void q_type<Qtype>::q(Qtype num)
{
if (tail+1==head || (tail+1==SIZE && !head)) {
cout << "Full" ;
return;
}
tail++;
if (tail==SIZE) tail = 0; // замыкание цикла
queue[tail] = num;
}
// Удаление значения из очереди
template <class Qtype>
Qtype q_type<Qtype>::deq()
{
if (head == tail) {
cout << "Pusto";
return 0; // очередь пуста или какая-то иная ошибка
}
head++;
if(head==SIZE) head = 0; // замыкание цикла
return queue[head];
}
template <class Qtype>
void q_type<Qtype>::print()
{
head++;
cout<<queue[head]<<endl;
if (head==tail) head=0;
}
void main()
{
q_type<char> q2;
int i;
for(i=1; i<10; i++){// dobavka
q2.q(i-1+'A');
}
cout<<"Zapolneno!"<<endl;
cout<<"Output on screen: "<<endl;
for(i=1; i<10; i++){// simple output on screen
q2.print();
}
cout<<endl;
cout <<"Izvlechem 1 element "<<i<<" "<< q2.deq() <<endl;
getchar();
}
Это похоже на очередь???