#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 6
int queue[MAX_SIZE];
int front = 0;
int rear = 0;
int is_empty(){
if(front == rear){
return 1;
}
else{
return 0;
}
}
int is_full(){
if(front == (rear + 1)%MAX_SIZE ){
return 1;
}
else{
return 0;
}
}
void enqueue(int e){
if(is_full()){
printf("Full\n");
exit(0);
}
else{
rear = (rear + 1)%MAX_SIZE;
queue[rear] = e;
}
}
int dequeue(){
if(is_empty()){
printf("Empty\n");
exit(0);
}
else{
front = (front + 1)%MAX_SIZE;
return queue[front];
}
}
void print_queue(){
if(is_empty()){
printf("Empty\n");
return;
}
else{
int cnt = (rear - front + MAX_SIZE)%MAX_SIZE;
int a = (front + 1)%MAX_SIZE;
for(int i = 0 ; i < cnt ; i++){
printf("%d ", queue[a]);
a = (a+1)%MAX_SIZE;
}
}
}
int main(void){
int n,x;
while(1){
scanf("%d", &n);
if(n == 0){
print_queue();
break;
}
else if(n == 1){
scanf("%d", &x);
enqueue(x);
}
else if(n == 2){
dequeue();
}
}
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: