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.

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

#define MAXLENGTH 5
class queue
{
	public:
	int arr[MAXLENGTH];
	int front,rear;

	public:
	queue()
	{
		front = rear = MAXLENGTH-1;    /* marks the front end of queue */

	}

	void insert(int a);
	int remove();
};

void queue::insert(int a)
{
	if(rear == MAXLENGTH-1)
		rear = 0;
	else
		rear++;

	if(rear == front)
	{
		printf("queue overflow");
		exit(1);
	}

	arr[rear]=a;
	return;
}





int queue::remove()
{
	if(rear == front)
	{
		printf("queue underflow");
		exit(1);
	}

	if(front == MAXLENGTH-1)
		front = 0;
	else
		front++;

	return(arr[front]);

}

void main()
{
	clrscr();
	queue q;
	q.insert(1);
	q.insert(2);
	q.insert(3);
	q.insert(4);
	q.remove();
	q.insert(5);
	printf("%d %d %d %d",q.remove(),q.remove(),q.remove(),q.remove());


	getch();
}									

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