SlideShare a Scribd company logo
1 of 2
Download to read offline
S4-3
Write a program in ‘C’ language to implement multiple stacks in a
single array.
#include<stdio.h>
#include<conio.h>
int sno,t1,t2;
int a[20];
void push(int,int);
void pop(int);
void disp();
void main()
{
int val,t=1,no;
clrscr();
t1=0;
t2=10;
while(t)
{
printf("n1.pushn2.popn3.exitn");
printf("enter your choice");
scanf("%d",&t);
switch(t)
{
case 1:
printf("enter the stack no:n");
scanf("%d",&sno);
printf("enter the value:n");
scanf("%d",&val);
push(sno,val);
disp();
break;
case 2:
printf("enter the stack no:n");
scanf("%d",&sno);
pop(sno);
disp();
break;
case 3:
exit();
}
}
getch();
}
void disp()
{
int ts1=t1, ts2=t2;
printf("nStack 1:n ");
if (ts1 <= 0)
printf ("Empty");
while(ts1>0)
printf("%dt", a[ts1--]);
printf("nStack 1:n ");
if (ts2 <= 10)
Page 1
S4-3
printf ("Empty");
while(ts2>10)
printf("%dt", a[ts2--]);
}
void push(int sno,int val)
{
switch(sno)
{
case 1:
if((++t1)==10)
printf("stack 1:overflown");
else
a[t1]=val;
break;
case 2:
if(++t2==20)
printf("stack 2:overflown");
else
a[t2]=val;
break;
}
}
void pop(int sno)
{
switch(sno)
{
case 1:
if(t1<=0)
printf("stack 1:emptyn");
else
{
printf("%dn",a[t1]);
t1--;
}
break;
case 2:
if(t2<=10)
printf("stack 2:emptyn");
else
{
printf("%dn",a[t2]);
t2--;
}
break;
}
}
Page 2

More Related Content

What's hot (20)

質數的判斷
質數的判斷質數的判斷
質數的判斷
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Pilas
PilasPilas
Pilas
 
listing output program C
listing output program Clisting output program C
listing output program C
 
B.f.s
B.f.sB.f.s
B.f.s
 
Heep implementation in c
Heep implementation in cHeep implementation in c
Heep implementation in c
 
Numeros primos
Numeros primosNumeros primos
Numeros primos
 
Fcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt ChartFcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt Chart
 
Alocação Dinâmica em C
Alocação Dinâmica em CAlocação Dinâmica em C
Alocação Dinâmica em C
 
Cpro
CproCpro
Cpro
 
Trabajo de programacion
Trabajo de programacionTrabajo de programacion
Trabajo de programacion
 
Scanfill polygon
Scanfill polygonScanfill polygon
Scanfill polygon
 
Linker
LinkerLinker
Linker
 
Ejercicios.
Ejercicios. Ejercicios.
Ejercicios.
 
C - Pattern - Code - [Future Programming]
C - Pattern - Code - [Future Programming]C - Pattern - Code - [Future Programming]
C - Pattern - Code - [Future Programming]
 
Par o impar
Par o imparPar o impar
Par o impar
 
Vcs6
Vcs6Vcs6
Vcs6
 
Practica 08 bison
Practica 08 bisonPractica 08 bison
Practica 08 bison
 
Doi xung mang mot chieu
Doi xung mang mot chieuDoi xung mang mot chieu
Doi xung mang mot chieu
 
Quick sort
Quick sortQuick sort
Quick sort
 

More from Dr. Loganathan R

Ch 6 IoT Processing Topologies and Types.pdf
Ch 6 IoT Processing Topologies and Types.pdfCh 6 IoT Processing Topologies and Types.pdf
Ch 6 IoT Processing Topologies and Types.pdfDr. Loganathan R
 
IoT Sensing and Actuation.pdf
 IoT Sensing and Actuation.pdf IoT Sensing and Actuation.pdf
IoT Sensing and Actuation.pdfDr. Loganathan R
 
Program in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersProgram in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersDr. Loganathan R
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.Dr. Loganathan R
 
Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3Dr. Loganathan R
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Dr. Loganathan R
 
Bcsl 033 data and file structures lab s4-2
Bcsl 033 data and file structures lab s4-2Bcsl 033 data and file structures lab s4-2
Bcsl 033 data and file structures lab s4-2Dr. Loganathan R
 
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Dr. Loganathan R
 
Bcsl 033 data and file structures lab s3-2
Bcsl 033 data and file structures lab s3-2Bcsl 033 data and file structures lab s3-2
Bcsl 033 data and file structures lab s3-2Dr. Loganathan R
 
Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1Dr. Loganathan R
 
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Dr. Loganathan R
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Dr. Loganathan R
 
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Dr. Loganathan R
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Dr. Loganathan R
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Dr. Loganathan R
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Dr. Loganathan R
 
Introduction to Information Security
Introduction to Information SecurityIntroduction to Information Security
Introduction to Information SecurityDr. Loganathan R
 
Mcs 012 computer organisation and assemly language programming- ignou assignm...
Mcs 012 computer organisation and assemly language programming- ignou assignm...Mcs 012 computer organisation and assemly language programming- ignou assignm...
Mcs 012 computer organisation and assemly language programming- ignou assignm...Dr. Loganathan R
 
Session 9 4 alp to display the current system time using dos int 21 h
Session 9  4 alp to display the current system time using dos int 21 hSession 9  4 alp to display the current system time using dos int 21 h
Session 9 4 alp to display the current system time using dos int 21 hDr. Loganathan R
 

More from Dr. Loganathan R (20)

Ch 6 IoT Processing Topologies and Types.pdf
Ch 6 IoT Processing Topologies and Types.pdfCh 6 IoT Processing Topologies and Types.pdf
Ch 6 IoT Processing Topologies and Types.pdf
 
IoT Sensing and Actuation.pdf
 IoT Sensing and Actuation.pdf IoT Sensing and Actuation.pdf
IoT Sensing and Actuation.pdf
 
Ch 4 Emergence of IoT.pdf
Ch 4 Emergence of IoT.pdfCh 4 Emergence of IoT.pdf
Ch 4 Emergence of IoT.pdf
 
Program in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersProgram in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointers
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.
 
Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2
 
Bcsl 033 data and file structures lab s4-2
Bcsl 033 data and file structures lab s4-2Bcsl 033 data and file structures lab s4-2
Bcsl 033 data and file structures lab s4-2
 
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3
 
Bcsl 033 data and file structures lab s3-2
Bcsl 033 data and file structures lab s3-2Bcsl 033 data and file structures lab s3-2
Bcsl 033 data and file structures lab s3-2
 
Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-1
 
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
Introduction to Information Security
Introduction to Information SecurityIntroduction to Information Security
Introduction to Information Security
 
Mcs 012 computer organisation and assemly language programming- ignou assignm...
Mcs 012 computer organisation and assemly language programming- ignou assignm...Mcs 012 computer organisation and assemly language programming- ignou assignm...
Mcs 012 computer organisation and assemly language programming- ignou assignm...
 
Session 9 4 alp to display the current system time using dos int 21 h
Session 9  4 alp to display the current system time using dos int 21 hSession 9  4 alp to display the current system time using dos int 21 h
Session 9 4 alp to display the current system time using dos int 21 h
 

Bcsl 033 data and file structures lab s4-3

  • 1. S4-3 Write a program in ‘C’ language to implement multiple stacks in a single array. #include<stdio.h> #include<conio.h> int sno,t1,t2; int a[20]; void push(int,int); void pop(int); void disp(); void main() { int val,t=1,no; clrscr(); t1=0; t2=10; while(t) { printf("n1.pushn2.popn3.exitn"); printf("enter your choice"); scanf("%d",&t); switch(t) { case 1: printf("enter the stack no:n"); scanf("%d",&sno); printf("enter the value:n"); scanf("%d",&val); push(sno,val); disp(); break; case 2: printf("enter the stack no:n"); scanf("%d",&sno); pop(sno); disp(); break; case 3: exit(); } } getch(); } void disp() { int ts1=t1, ts2=t2; printf("nStack 1:n "); if (ts1 <= 0) printf ("Empty"); while(ts1>0) printf("%dt", a[ts1--]); printf("nStack 1:n "); if (ts2 <= 10) Page 1
  • 2. S4-3 printf ("Empty"); while(ts2>10) printf("%dt", a[ts2--]); } void push(int sno,int val) { switch(sno) { case 1: if((++t1)==10) printf("stack 1:overflown"); else a[t1]=val; break; case 2: if(++t2==20) printf("stack 2:overflown"); else a[t2]=val; break; } } void pop(int sno) { switch(sno) { case 1: if(t1<=0) printf("stack 1:emptyn"); else { printf("%dn",a[t1]); t1--; } break; case 2: if(t2<=10) printf("stack 2:emptyn"); else { printf("%dn",a[t2]); t2--; } break; } } Page 2