0% found this document useful (0 votes)
16 views5 pages

Exp 3

Uploaded by

2403fqcjkvyash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Exp 3

Uploaded by

2403fqcjkvyash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<process.h>

#define MAX 100

int front=-1,rear=-1,queue[MAX];

void push(); void pop(); void

display(); void main()

clrscr();

int

choice;

while(1)

printf("\n1.push\t2.pop\t3.display\t4.exit\n");

scanf("%d",&choice);

switch(choice)

{ case

1:push();

break;

case 2:pop();

break;

case 3:display();

break;

case 4:exit(1); default:printf("Invalid choice!!!\n");

getch(); }

void push()

{
int val; if(front==-

1) { front++;

rear++;

printf("Enter the

element\n");

scanf("%d",&val);

queue[rear]=val; }

else

if(rear==MAX-1)

printf("Queue is full\n");

else

{ rear++; printf("Enter the

element\n");

scanf("%d",&val);

queue[rear]=val;

} void

pop()

int val; if(front>rear) {

printf("Queue is Empty\n");

else if(front==-1)

{ printf("Queue is

empty\n"); } else

if(front==0&&rear==0)

{ val=queue[front];

printf("Deleted
element:%d",val); front=-1;

rear=-1;

else

{ val=queue[front];

printf("Deleted

element:%d",val); front++;

} void

display()

int i;

if(front==-1) {

printf("Queue is empty\n");

else {

printf("Queue:\n");

for(i=front;i<=rear;i++)

printf("%d\n",queue[i]);

OUTPUT:

1.Push 2.Pop

Enter the choice

Enter the element

43
3.Display 4.Exit

1.Push 2.Pop

Enter the choice

Enter the element

25

3.Display 4.Exit

1.Push 2.Pop

Enter the choice

Enter the element

65

3.Display 4.Exit

1.Push 2.Pop

Enter the choice

Deleted element: 43

3.Display 4.Exit

1.Push 2.Pop

Enter the choice

Queue:

25

65
3.Display 4.Exit

1.Push 2.Pop 3.Display 4.Exit

Enter the choice

You might also like