SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Bubble sort
Bubble sortBubble sort
Bubble sort
Hitesh Kumar
 
Pilas
PilasPilas
Pilas
Cerdorock
 
listing output program C
listing output program Clisting output program C
listing output program C
AdjievanGestu
 
Heep implementation in c
Heep implementation in cHeep implementation in c
Heep implementation in c
HapPy SumOn
 
Fcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt ChartFcfs Cpu Scheduling With Gantt Chart
Fcfs Cpu Scheduling With Gantt Chart
One97 Communications Limited
 
Alocação Dinâmica em C
Alocação Dinâmica em CAlocação Dinâmica em C
Alocação Dinâmica em C
Luiz Francisco Bozo
 
Scanfill polygon
Scanfill polygonScanfill polygon
Scanfill polygon
Sonia Pahuja
 
Linker
LinkerLinker
Linker
Satyamevjayte Haxor
 
Ejercicios.
Ejercicios. Ejercicios.
Ejercicios.
Jose Dani
 
C - Pattern - Code - [Future Programming]
C - Pattern - Code - [Future Programming]C - Pattern - Code - [Future Programming]
C - Pattern - Code - [Future Programming]
Future Programming
 
Practica 08 bison
Practica 08 bisonPractica 08 bison
Practica 08 bison
elyescobar
 
Doi xung mang mot chieu
Doi xung mang mot chieuDoi xung mang mot chieu
Doi xung mang mot chieu
Nguyen Van Hung
 
Quick sort
Quick sortQuick sort
Quick sort
Hitesh Kumar
 

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
Dr. Loganathan R
 
IoT Sensing and Actuation.pdf
 IoT Sensing and Actuation.pdf IoT Sensing and Actuation.pdf
IoT Sensing and Actuation.pdf
Dr. Loganathan R
 
Ch 4 Emergence of IoT.pdf
Ch 4 Emergence of IoT.pdfCh 4 Emergence of IoT.pdf
Ch 4 Emergence of IoT.pdf
Dr. 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 pointers
Dr. 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-3
Dr. 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-2
Dr. 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-2
Dr. 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-3
Dr. 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-2
Dr. 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-1
Dr. 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-3
Dr. 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-2
Dr. 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-1
Dr. 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-4
Dr. 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-3
Dr. 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-1
Dr. Loganathan R
 
Introduction to Information Security
Introduction to Information SecurityIntroduction to Information Security
Introduction to Information Security
Dr. 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 h
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.pdf
Dr. Loganathan R
 
IoT Sensing and Actuation.pdf
 IoT Sensing and Actuation.pdf IoT Sensing and Actuation.pdf
IoT Sensing and Actuation.pdf
Dr. 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 pointers
Dr. 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-3
Dr. 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-2
Dr. 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-2
Dr. 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-3
Dr. 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-2
Dr. 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-1
Dr. 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-3
Dr. 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-2
Dr. 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-1
Dr. 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-4
Dr. 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-3
Dr. 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-1
Dr. Loganathan R
 
Introduction to Information Security
Introduction to Information SecurityIntroduction to Information Security
Introduction to Information Security
Dr. 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 h
Dr. Loganathan R
 
Ad

Recently uploaded (9)

Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...
Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...
Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...
woorinplies
 
15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS
15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS
15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS
ssuser787edf
 
Komyuterga latex dasturiy ta'minotini o'rnatish.pptx
Komyuterga latex dasturiy ta'minotini o'rnatish.pptxKomyuterga latex dasturiy ta'minotini o'rnatish.pptx
Komyuterga latex dasturiy ta'minotini o'rnatish.pptx
samexpoler
 
DOKUMEN STANDARD KURIKULUM STAM 2025 TERBARU
DOKUMEN STANDARD KURIKULUM STAM 2025 TERBARUDOKUMEN STANDARD KURIKULUM STAM 2025 TERBARU
DOKUMEN STANDARD KURIKULUM STAM 2025 TERBARU
Nur Zalikha Mohamad Zaki
 
humanrights-240228064302-b0c61...0f4.pptx
humanrights-240228064302-b0c61...0f4.pptxhumanrights-240228064302-b0c61...0f4.pptx
humanrights-240228064302-b0c61...0f4.pptx
romypaulbabaran8
 
ACTIVIDADES PARA REALIZAR EN CLASES EN LINEA
ACTIVIDADES PARA REALIZAR EN CLASES EN LINEAACTIVIDADES PARA REALIZAR EN CLASES EN LINEA
ACTIVIDADES PARA REALIZAR EN CLASES EN LINEA
leeorma
 
karakter lampu suar dalam pencegahan bahaya di laut
karakter lampu suar dalam pencegahan bahaya di lautkarakter lampu suar dalam pencegahan bahaya di laut
karakter lampu suar dalam pencegahan bahaya di laut
badaklogam
 
New Microsoft PowerPoint Presentation (3).pptx
New Microsoft PowerPoint Presentation (3).pptxNew Microsoft PowerPoint Presentation (3).pptx
New Microsoft PowerPoint Presentation (3).pptx
deepanshu98739
 
كتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdf
كتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdfكتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdf
كتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdf
alzryqyh38
 
Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...
Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...
Scandinavian Biographical Index 2nd Cumulated And Enlarged Edition Laureen Ba...
woorinplies
 
15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS
15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS
15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS15MAY 2025 PS
ssuser787edf
 
Komyuterga latex dasturiy ta'minotini o'rnatish.pptx
Komyuterga latex dasturiy ta'minotini o'rnatish.pptxKomyuterga latex dasturiy ta'minotini o'rnatish.pptx
Komyuterga latex dasturiy ta'minotini o'rnatish.pptx
samexpoler
 
DOKUMEN STANDARD KURIKULUM STAM 2025 TERBARU
DOKUMEN STANDARD KURIKULUM STAM 2025 TERBARUDOKUMEN STANDARD KURIKULUM STAM 2025 TERBARU
DOKUMEN STANDARD KURIKULUM STAM 2025 TERBARU
Nur Zalikha Mohamad Zaki
 
humanrights-240228064302-b0c61...0f4.pptx
humanrights-240228064302-b0c61...0f4.pptxhumanrights-240228064302-b0c61...0f4.pptx
humanrights-240228064302-b0c61...0f4.pptx
romypaulbabaran8
 
ACTIVIDADES PARA REALIZAR EN CLASES EN LINEA
ACTIVIDADES PARA REALIZAR EN CLASES EN LINEAACTIVIDADES PARA REALIZAR EN CLASES EN LINEA
ACTIVIDADES PARA REALIZAR EN CLASES EN LINEA
leeorma
 
karakter lampu suar dalam pencegahan bahaya di laut
karakter lampu suar dalam pencegahan bahaya di lautkarakter lampu suar dalam pencegahan bahaya di laut
karakter lampu suar dalam pencegahan bahaya di laut
badaklogam
 
New Microsoft PowerPoint Presentation (3).pptx
New Microsoft PowerPoint Presentation (3).pptxNew Microsoft PowerPoint Presentation (3).pptx
New Microsoft PowerPoint Presentation (3).pptx
deepanshu98739
 
كتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdf
كتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdfكتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdf
كتاب الإتقان في متشابهات القرآن الطبعة الأولى.pdf
alzryqyh38
 
Ad

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
  翻译: