C program for implementation of linear queue using array

Posted: April 3, 2012 in Lab 8
/*Linear Queue implementation using linked list
Written by Shivam Rana
Date- 2-4-12   */
#include<stdio.h>
int queue[100],front=0,rear=-1,count=0;
void push(int n)
{
queue[++rear]=n;
count++;
}
void pop(void)
{
if(count==0)
printf("Queue is empty\n");
	else
	{
count--;
		printf("Number poped from queue is %d\n",queue[front++]);
	}
}
void display()
{
int i;
if(count==0)
printf("Empty");
else
for(i=front;i<=rear;i++)
printf("%d ",queue[i]);
printf("\n");
}
int size(void)
{
return count;
}
int main()
{
int n,ch=10;
while(ch!=0)
{
printf("\n       What do you want to do??\n");
printf("1.Push\n");
printf("2.Pop\n");
printf("3.SizeOfQueue\n");
printf("4.Display\n");
printf("0.EXIT\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("What no. do you want to push in queue\n");
scanf("%d",&n);
push(n);
break;
}
case 2:
{
pop();

break;
}
case 3:
{
n=size();
printf("Size of queue is %d\n",n);
break;
}
case 4:
{
printf("Queue is -->> ");
display();
}
case 0:
break;
}
}
}
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s