/* PROGRAM TO IMPLEMENT LINEAR QUEUE USING ARRAY*/
/*include header files*/
#include<stdio.h>
#include<conio.h>
int queue[5];
long front,rear;
void main()
{
int choice,info;
clrscr();
//Initialising queue
initqueue();
while(1)
{
clrscr();
//Displaying menu
printf(" MENU \n");
printf("1.Push an element in queue\n");
printf("2.Pop an element from queue\n");
printf("3.Display the queue\n");
printf("4.Exit!\n");
printf("Your choice: ");
scanf("%i",&choice);
switch(choice)
{
case 1:if(rear<4)
{
printf("enter the number");
scanf("%d",&info);
if (front==-1)
{
front=0;
rear=0;
}
else
rear=rear+1;
queue[rear]=info;
}
else
printf("queue is full");
getch();
break;
case 2: int info;
if(front!=-1)
{
info=queue[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else
front=front+1;
printf("no deleted is = %d",info);
}
else
printf("queue is empty");
getch();
break;
case 3: display();
getch();
break;
case 4: exit();
break;
default:printf("You entered wrong choice!");
getch();
break;
}
}
}
void initqueue()
{
//Initialising front & rear to -1
front=rear=-1;
}
/*displays the current position of the queue*/
void display()
{
int i; //For loop driver
//Displaying elements in queue
for(i=front;i<=rear;i++)
printf("%i\n",queue[i]);
}
/*output of the program*/
for more codes you can visit -http://codesofprogramming.blogspot.in/
/*include header files*/
#include<stdio.h>
#include<conio.h>
int queue[5];
long front,rear;
void main()
{
int choice,info;
clrscr();
//Initialising queue
initqueue();
while(1)
{
clrscr();
//Displaying menu
printf(" MENU \n");
printf("1.Push an element in queue\n");
printf("2.Pop an element from queue\n");
printf("3.Display the queue\n");
printf("4.Exit!\n");
printf("Your choice: ");
scanf("%i",&choice);
switch(choice)
{
case 1:if(rear<4)
{
printf("enter the number");
scanf("%d",&info);
if (front==-1)
{
front=0;
rear=0;
}
else
rear=rear+1;
queue[rear]=info;
}
else
printf("queue is full");
getch();
break;
case 2: int info;
if(front!=-1)
{
info=queue[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else
front=front+1;
printf("no deleted is = %d",info);
}
else
printf("queue is empty");
getch();
break;
case 3: display();
getch();
break;
case 4: exit();
break;
default:printf("You entered wrong choice!");
getch();
break;
}
}
}
void initqueue()
{
//Initialising front & rear to -1
front=rear=-1;
}
/*displays the current position of the queue*/
void display()
{
int i; //For loop driver
//Displaying elements in queue
for(i=front;i<=rear;i++)
printf("%i\n",queue[i]);
}
/*output of the program*/
for more codes you can visit -http://codesofprogramming.blogspot.in/
No comments:
Post a Comment