Cicular Queue(C)
      This is a program implementing a circular queue. A circular queue is nothing but a queue which inserts values in circular order.
 /* circular queue in c */

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

#define MAXLENGTH 5

struct queue
{
	int arr[MAXLENGTH];
	int front,rear;
};

int empty(struct queue *pq)
{
	return((pq->front == pq->rear)? 1 : 0);
}

int remove(struct queue *pq)
{
	if(empty(pq))
	{
		printf("\n queue underflow");
		exit(1);
	}

	if(pq->front == MAXLENGTH-1)
		pq->front = 0;
	else
		(pq->front)++;
	return(pq->arr[pq->front]);
}

void insert(struct queue *pq, int x)
{
	if(pq->rear == MAXLENGTH-1)
		pq->rear = 0;
	else
		(pq->rear)++;
	if(pq->rear==pq->front)
	{
		printf("queue overflow ");
		exit(1);
	}
	pq->arr[pq->rear] = x ;
	return;
}

void main()
{
	clrscr();
	int i ;

	struct queue q;
	q.front = q.rear = MAXLENGTH-1;
	insert(&q,1);
	insert(&q,2);
	insert(&q,3);
	insert(&q,4);

	i=remove(&q);
	printf("\n %d",i);
	i=remove(&q);
	printf("\n %d",i);
	i=remove(&q);
	printf("\n %d",i);
	i=remove(&q);
	printf("\n %d",i);
	i=remove(&q);
	printf("\n %d",i);
	fflush(stdin);
	getch();


}									

Download Program
Did You Know ?
IP address is a numerical label that is assigned to devices participating in a computer network. Read More