Embed presentation
Download to read offline
![S5-4
Write a program in ‘C’ language to implement a queue using two stacks.
#include<stdio.h>
int stak1[10], stak2[10], n, top,top1;
/*add elements to que*/
void add()
{
while(top>0)
{
scanf("%d",&n);
stak1[top]=n;
top++;
}
while(top<10)
{
stak2[top1]=stak1[top];
top1++; top--;
}
}
/*delete elements from que*/
void del()
{
int n;
while(top1>0)
n=stak2[top1];
top1--;
}
/*display elements*/
void display()
{
int i=top1;
while(i>0)
{
printf("n%d",stak2[i]);
i++;
}
}
main()
{
printf("nEnter 10 numbersn");
add();
display();
del();
printf("Elements in the que after deleting first elen");
display();
del();
printf("nElements after deleting second elen");
display();
getch();
}
Page 1](https://image.slidesharecdn.com/bcsl-033dataandfilestructureslabs5-4-160515012628/75/Implement-a-queue-using-two-stacks-1-2048.jpg)

The document presents a C language program that implements a queue using two stacks. It includes functions to add and delete elements from the queue, as well as display its contents. The program prompts the user to enter numbers and demonstrates the queue operations with sample outputs.
![S5-4
Write a program in ‘C’ language to implement a queue using two stacks.
#include<stdio.h>
int stak1[10], stak2[10], n, top,top1;
/*add elements to que*/
void add()
{
while(top>0)
{
scanf("%d",&n);
stak1[top]=n;
top++;
}
while(top<10)
{
stak2[top1]=stak1[top];
top1++; top--;
}
}
/*delete elements from que*/
void del()
{
int n;
while(top1>0)
n=stak2[top1];
top1--;
}
/*display elements*/
void display()
{
int i=top1;
while(i>0)
{
printf("n%d",stak2[i]);
i++;
}
}
main()
{
printf("nEnter 10 numbersn");
add();
display();
del();
printf("Elements in the que after deleting first elen");
display();
del();
printf("nElements after deleting second elen");
display();
getch();
}
Page 1](https://image.slidesharecdn.com/bcsl-033dataandfilestructureslabs5-4-160515012628/75/Implement-a-queue-using-two-stacks-1-2048.jpg)