SlideShare a Scribd company logo
1 of 6
Stack
-An implementation of Stack using
ARRAY in C.
The Main Module
#include<stdio.h>
#include<stdlib.h>
void push(), pop(), display();
int top=-1,stack[5];
int main()
{
int choice;
while(1)
{
printf("n----Stack Menu----n");
printf("1. Push.n");
printf("2. Pop.n");
printf("3. Display.n");
printf("4. Exit.n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
break;
default: printf("Invalid option.");
}
}
}
Insert An Element Into Stack
void push()
{
if(top<4)
{
int num;
printf("Enter an integer value: ");
scanf("%d",&num);
top++;
stack[top]=num;
}
else
{
printf("nStack Overflow.n");
}
display();
}
Delete An Element From Stack
void pop()
{
if(top>=0)
{
printf("Item popped is: %d",stack[top]);
top--;
}
else
{
printf("nStack Underflow.n");
}
display();
}
Display The Elements In Stack
void display()
{
int head=top;
if(head>=0)
{
printf("The items in the stack are: ");
while(head!=-1)
{
printf("n%d",stack[head]);
head--;
}
}
else
{
printf("nStack empty.n");
}
}
Presented By:-
Sayantan Sur
Thank You

More Related Content

What's hot

What's hot (20)

Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
 
Arrays
ArraysArrays
Arrays
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Stack
StackStack
Stack
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Heaps
HeapsHeaps
Heaps
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 

Viewers also liked (10)

Hoja de vida
Hoja de vida Hoja de vida
Hoja de vida
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stacks
StacksStacks
Stacks
 
Decision Support System(DSS)
Decision Support System(DSS)Decision Support System(DSS)
Decision Support System(DSS)
 

Similar to Stack using Array

Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 

Similar to Stack using Array (20)

Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Array menu
Array menuArray menu
Array menu
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
Short Review of Stack
Short Review of StackShort Review of Stack
Short Review of Stack
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
week-15x
week-15xweek-15x
week-15x
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Circular queue
Circular queueCircular queue
Circular queue
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Data Structures : array operations in c program
Data Structures : array operations in c program Data Structures : array operations in c program
Data Structures : array operations in c program
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Array list
Array listArray list
Array list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
 
#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx
 
Qprgs
QprgsQprgs
Qprgs
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Array imp of list
Array imp of listArray imp of list
Array imp of list
 

More from Sayantan Sur (6)

Image Encryption and Compression
Image Encryption and Compression Image Encryption and Compression
Image Encryption and Compression
 
Network Security
Network SecurityNetwork Security
Network Security
 
Visual Studio IDE
Visual Studio IDEVisual Studio IDE
Visual Studio IDE
 
Ethical Hacking
Ethical HackingEthical Hacking
Ethical Hacking
 
Phising
PhisingPhising
Phising
 
International Terrorism
International Terrorism International Terrorism
International Terrorism
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Stack using Array

  • 1. Stack -An implementation of Stack using ARRAY in C.
  • 2. The Main Module #include<stdio.h> #include<stdlib.h> void push(), pop(), display(); int top=-1,stack[5]; int main() { int choice; while(1) { printf("n----Stack Menu----n"); printf("1. Push.n"); printf("2. Pop.n"); printf("3. Display.n"); printf("4. Exit.n"); printf("Enter your choice: "); scanf("%d",&choice); switch(choice) { case 1: push(); break; case 2: pop(); break; case 3: display(); break; case 4: exit(0); break; default: printf("Invalid option."); } } }
  • 3. Insert An Element Into Stack void push() { if(top<4) { int num; printf("Enter an integer value: "); scanf("%d",&num); top++; stack[top]=num; } else { printf("nStack Overflow.n"); } display(); }
  • 4. Delete An Element From Stack void pop() { if(top>=0) { printf("Item popped is: %d",stack[top]); top--; } else { printf("nStack Underflow.n"); } display(); }
  • 5. Display The Elements In Stack void display() { int head=top; if(head>=0) { printf("The items in the stack are: "); while(head!=-1) { printf("n%d",stack[head]); head--; } } else { printf("nStack empty.n"); } }