#include <stdio.h>
#include<stdlib.h>
#define datatype char
#define MAXSIZE 100
typedef struct
{
datatype data[MAXSIZE];
int front,rear;
}SEQQUEUE;
SEQQUEUE *q;
void Init_Queue(SEQQUEUE *q)
{
q->front=0;
q->rear=0;
}
int Queue_Emppty(SEQQUEUE *q)
{
if(q->front==q->rear)
return 1;
else
return 0;
}
void Add_Queue(SEQQUEUE *q,datatype x)
{
if((q->rear+1) % MAXSIZE==q->front)
printf("Queue full\n");
else
{
q->rear=(q->rear+1)%MAXSIZE;
q->data[q->rear]=x;
}
}
datatype Gethead_Queue(SEQQUEUE *q)
{
datatype x;
if(Queue_Emppty(q))
x=0;
else
x=q->data[(q->front+1)%MAXSIZE];
return x;
}
datatype Del_Queue(SEQQUEUE *q)
{
datatype x;
if(Queue_Emppty(q))
{
printf("Queue empty\n");
x=0;
}
else
{
q->front=(q->front+1)%MAXSIZE;
x=q->data[q->front];
}
return x;
}
void Clear_Queue(SEQQUEUE *q)
{
q->front=0;
q->rear=0;
}
int QueueLength(SEQQUEUE *q)
{
int len;
len=(MAXSIZE+q->rear-q->front)%MAXSIZE;
return len;
}
int main()
{
SEQQUEUE queue,*q;
char ch;
q=&queue;
Init_Queue(q);
scanf("%c",&ch);
while(ch!='\n')
{
Add_Queue(q,ch);
scanf("%c",&ch);
}
printf("%d\n",QueueLength(q));
while (!Queue_Emppty(q))
{
ch=Gethead_Queue(q);
printf("%c",ch);
Del_Queue(q);
}
}