,head == tail ,
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;
typedef struct node
{
string key;
string value;
node *next;
}node;
#define LEN 20
typedef int Elemtype;
class Queue
{
public:
int head;
int tail;
int flag;
Elemtype q[LEN];
Queue()
{
head = tail = 0;
flag = 0;
memset(q,-1,sizeof(q));
}
int enqueue(Elemtype e)
{
if( head == tail && flag == 1)
{
cout << "queue full" << endl;
return -1;
}
q[tail] = e;
tail = (tail + 1) % LEN;
if(head == tail)flag = 1;
return 0;
}
int dequeue(Elemtype &e)
{
if(head == tail && flag == 0)
{
cout << "queue empty" << endl;
return -1;
}
e = q[head];
head = (head + 1) % LEN;
if(head == tail) flag = 0;
return 0;
}
};
int main()
{
class Queue que;
int i ;
Elemtype elem;
for(i = 0;i < 1000;i ++)
{
if(i % 3)
{
que.enqueue(i);
}
else
{
int ret = que.dequeue(elem);
if(ret >= 0)cout << "i = " << i << " dequeue is :" << elem << endl;
}
system("pause");
}
return 0;
}