#include <stdio.h>

#define SIZE 5
int queue[SIZE];
int head, tail;

void enqueue(int value);
int dequeue(void);

int main(void)
{
	head=tail=0;
	int resp,data, i;
	
	while(1){
		printf("1:enqueue 2:dequeue 0:end : ");scanf("%d",&resp);
		
		if(!resp) break;
		
		switch(resp){
			case 1: printf("enqueue: "); scanf("%d",&data);
			        enqueue(data);
			        break;
			case 2: dequeue();
			        break;
		}
		printf("head=%d, tail=%d\n",head,tail);
	}
	printf("\n");
	i=head;
	while(i!=tail){
		printf("queue[%d]=%d\n",i,queue[i]);
		i++;
		i=i%SIZE;
	}
	return 0;
}

void enqueue(int value)
{
	if(head==(tail+1)%SIZE){
		printf("キューは満杯で入りませんでした\n");
	}else{
		queue[tail++]=value;
	}
	tail=tail%SIZE;
}

int dequeue(void)
{
	int value;
	if(head==tail){
		printf("キューは空で取り出せませんでした\n");
		return 0;
	}else{
		value=queue[head++];
	}
	head=head%SIZE;
	return value;
}

	// your code goes here

