// StaticQuene.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
struct StaticQuene
{
private:
	char buff[10];
	int front;
	int rear;
public:
	bool isFull;
	bool isEmpty;
	StaticQuene()
	{
		//buff[0]=c;
		front=0;
		rear=0;
		isFull=false;
		isEmpty=true;
	}
	bool Enquene(char c)
	{
		if(isFull)
			return false;
		buff[rear]=c;
		rear=++rear%10;
		if(rear==front)
		{
			isFull=true;
			isEmpty=false;
		}
		else
		{
			isFull=false;
			isEmpty=false;
		}
		return true;

	}
	bool OutQuene(char& c)
	{
		if(isEmpty)
			return false;
		c=buff[front];
		front=++front%10;
		if(rear==front)
		{
			isEmpty=true;
			isFull=false;
		}
		else
		{
			isFull=false;
			isEmpty=false;
		}
		return true;
	}
	int getLength()
	{
		if (rear>front)
			return (rear-front);
		else if(rear==front)
			return isFull?10:0;
		else
			return (rear-front+10);
	}
};
int main(int argc, char* argv[])
{
	StaticQuene quene;
	int i=0;
	char c;
	while(!quene.isFull)
	{
	     quene.Enquene('a'+i++);
		 printf("%d ",quene.getLength());
	}
	printf("\n");
	while(!quene.isEmpty)
	{
	quene.OutQuene(c);
	printf("%c %d;",c,quene.getLength());
	}
	printf("=======================\n");
	 i=0;
	while(!quene.isFull)
	{
	     quene.Enquene('a'+i++);
		 printf("%d ",quene.getLength());
	}
	printf("\n");
	while(!quene.isEmpty)
	{
	quene.OutQuene(c);
	printf("%c %d;",c,quene.getLength());
	}
	printf("=======================\n");
	return 0;
}

/*
1 2 3 4 5 6 7 8 9 10
a 9;b 8;c 7;d 6;e 5;f 4;g 3;h 2;i 1;j 0;=======================
1 2 3 4 5 6 7 8 9 10
a 9;b 8;c 7;d 6;e 5;f 4;g 3;h 2;i 1;j 0;=======================
Press any key to continue
*/