CODING:
#include<stdio.h>
#include<conio.h>
#define max 50
int q[max],front=-1,rear=-1;
void push();
void pop();
void peep();
void display();
void main()
{
int ch;
clrscr();
do
{
printf("\nS E L E C T C H O I C E");
printf("\n1.Insert Element.");
printf("\n2.Delete Element.");
printf("\n3.Peek.");
printf("\n4.Display Element.");
printf("\n5.Exit");
printf("\nEnter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peep();
break;
case 4:
display();
break;
case 5:
return;
default:
printf("TRY AGAIN.");
break;
}
}while(ch!=5);
getch();
}
void push()
{
int num;
printf("Enter the Number:");
scanf("%d",&num);
if(rear==max-1)
printf("Queue id overflow.");
if(rear==-1 && front==-1)
front=rear=0;
else
rear++;
q[rear]=num;
printf("%d is insert in Queue.",num);
}
void pop()
{
int val;
if(front==-1)
{
printf("Queue is Empty");
}
else
{
val=q[front];
printf("%d is deleted.",val);
}
if(front==rear)
{
front=rear=-1;
}
else
{
front++;
}
}
void peep()
{
if(front==-1)
printf("Queue is Empty");
else
printf("%d first element",q[front]);
}
void display()
{
int i;
if(front==-1)
printf("Queue is empty");
else
{
for(i=front;i<=rear;i++)
printf("\n%d",q[i]);
}
}
#include<stdio.h>
#include<conio.h>
#define max 50
int q[max],front=-1,rear=-1;
void push();
void pop();
void peep();
void display();
void main()
{
int ch;
clrscr();
do
{
printf("\nS E L E C T C H O I C E");
printf("\n1.Insert Element.");
printf("\n2.Delete Element.");
printf("\n3.Peek.");
printf("\n4.Display Element.");
printf("\n5.Exit");
printf("\nEnter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peep();
break;
case 4:
display();
break;
case 5:
return;
default:
printf("TRY AGAIN.");
break;
}
}while(ch!=5);
getch();
}
void push()
{
int num;
printf("Enter the Number:");
scanf("%d",&num);
if(rear==max-1)
printf("Queue id overflow.");
if(rear==-1 && front==-1)
front=rear=0;
else
rear++;
q[rear]=num;
printf("%d is insert in Queue.",num);
}
void pop()
{
int val;
if(front==-1)
{
printf("Queue is Empty");
}
else
{
val=q[front];
printf("%d is deleted.",val);
}
if(front==rear)
{
front=rear=-1;
}
else
{
front++;
}
}
void peep()
{
if(front==-1)
printf("Queue is Empty");
else
printf("%d first element",q[front]);
}
void display()
{
int i;
if(front==-1)
printf("Queue is empty");
else
{
for(i=front;i<=rear;i++)
printf("\n%d",q[i]);
}
}
Comments
Post a Comment