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

Implement a queue using two stacks.

  • 1.
    S5-4 Write a programin ‘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