Queue
      This is a program implementing queue. A queue is an ordered collection of items . Items are deleted and inseted in Fifo order.
/*
	* This is a program implementing queue.

	* A queue is an ordered collection of items from which
	  it means items may be deleted at one end called front and into
	  which items may be inserted at the other end called rear.

	* queue is also referred to as fifo i.e. first in and first
	  out.

*/

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

class queue
{
	public:
	int arr[100];
	int front,rear,size;

	public:
	queue()
	{
		front = 0;    /* marks the front end of queue */
		rear = -1;    /* marks the end of the queue*/
		size = 100;
	}

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

void queue::insert(int a)
{
	if(rear == -1 )
	{
		rear++;
		arr[rear] = a;
	}
	else if(rear<size-1)
	{
		rear++;

		if(rear == size-1)
		{
			printf("\nthe queue is full");
		}
		else
		{
			arr[rear] = a;
	       }
	}

}

int queue::remove()
{
	int i;
	if(front>rear)
	{
		printf(" \nthe queue is empty");
	}
	else
	{
		i = arr[front];
		front++;
		return i ;
	}
}

void main()
{
	clrscr();
	queue q;
	int i,k,a;

	printf("\n\t\tMenu");
	printf("\n to insert press 1");
	printf("\n to remove press 2");
	printf("\n to exit press 3");


	while(1)
	{
		printf("\n enter your choice :");
		scanf("%d",&k);

		switch(k)
		{
			case 1:
				printf("enter the value");
				scanf("%d",&a);
				q.insert(a);
				break;
			case 2:
				i = q.remove();
				printf(" the value is %d",i);
				break;
			case 3:
				exit(0);

		}

	}

	getch();
}


									

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