SlideShare a Scribd company logo
1 of 18
STACK ADT:
• Stack is a linear data structure in which the
insertion and deletion operations are
performed at only one end.
• In a stack, adding and removing of elements
are performed at a single position which is
known as "top".
• In stack, the insertion and deletion operations
are performed based on LIFO (Last In First
Out) & FILO (First In Last Out) principle.
• In a stack, the insertion operation is performed
using a function called "push" and deletion
operation is performed using a function
called "pop".
Operations on a Stack
• The following operations are performed on the
stack.
1. Push (To insert an element on to the stack)
2. Pop (To delete an element from the stack)
3. Display (To display elements of the stack)
• Stack data structure can be implemented in
two ways. They are as follows.
1. Using Array
2. Using Linked List
• When a stack is implemented using an array,
that stack can organize an only limited number
of elements.
• When a stack is implemented using a linked
list, that stack can organize an unlimited
number of elements.
Implementation of Stack using Array:
#include<stdio.h>
#include<conio.h>
#define SIZE 10
void push(int);
void pop();
void display();
int stack[SIZE], top = -1;
void main()
{
int value, choice;
clrscr();
while(1)
{
printf("nn***** MENU *****n");
printf("1.Push 2.Pop 3.Display 4.Exit");
printf("nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter the value to insert: ");
scanf("%d",&value);
push(value); break;
case 2: pop(); break;
case 3: display(); break;
case 4: exit(0);
default: printf("nWrong selection!");
}
} }
void push(int value)
{
if(top == SIZE-1)
printf("nStack is Full!");
else
{
top++;
stack[top] = value;
printf("nInsertion success!!!");
}
}
void pop()
{
if(top == -1)
printf("nStack is Empty!");
else
{
printf("nDeleted : %d", stack[top]);
top--;
}
}
void display()
{
if(top == -1)
printf("nStack is Empty!!!");
else
{
int i;
printf("nStack elements are:n");
for(i=top; i>=0; i--)
printf("%dn",stack[i]);
} }
Implementation of Stack using Linked List:
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
struct node *next;
}*top;
void push();
void pop();
void display();
void main()
{
int choice;
clrscr();
while(1)
{
printf("nn***** MENU *****n");
printf("1.Push 2.Pop 3.Display 4.Exit");
printf("nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: push(); break;
case 2: pop(); break;
case 3: display(); break;
case 4: exit(0);
default: printf("nWrong selection!");
}
}
}
void push ()
{
int val;
struct node *new =(struct node*)malloc(sizeof
(struct node));
printf("Enter the value");
scanf("%d",&val);
if(top == NULL)
{
new->data = val;
new->next = NULL;
top=new;
}
else
{
new->data = val;
new->next = top;
top=new;
}
}
void pop()
{
struct node *temp=top;
if (temp== NULL)
printf("Underflow");
else
{
printf(“Deleted element %d”,temp->data);
top = temp->next;
free(temp);
} }
void display()
{
struct node * temp =top;
if(temp == NULL)
printf("Stack is emptyn");
else
{
printf("Printing Stack elements n");
while(temp!=NULL)
{
printf("%dn",temp->data);
temp = temp ->next;
}
}
}
Application of Stack:
• Evaluating arithmetic expression
• Balancing the symbols
• Towers of Hanoi
• Function calls
• 8 Queen problem

More Related Content

What's hot

Stack1
Stack1Stack1
Stack1Iqrazb
 
Array imp of list
Array imp of listArray imp of list
Array imp of listElavarasi K
 
Grokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascriptGrokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascriptGrokking VN
 
New microsoft word document
New microsoft word documentNew microsoft word document
New microsoft word documentAbhishek Arya
 
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 Raghavendra Narayan
 
Python basic Program
Python basic ProgramPython basic Program
Python basic Programnuripatidar
 
C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5Rumman Ansari
 
Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...SAKSHISINGH486
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language 9096308941
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4Rumman Ansari
 
Functional Programming on Android: is it possible?
Functional Programming on Android: is it possible?Functional Programming on Android: is it possible?
Functional Programming on Android: is it possible?Lucas Albuquerque
 

What's hot (19)

Avl tree
Avl treeAvl tree
Avl tree
 
Stack1
Stack1Stack1
Stack1
 
Array imp of list
Array imp of listArray imp of list
Array imp of list
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Grokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascriptGrokking TechTalk #16: Maybe functor in javascript
Grokking TechTalk #16: Maybe functor in javascript
 
New microsoft word document
New microsoft word documentNew microsoft word document
New microsoft word document
 
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
 
Python basic Program
Python basic ProgramPython basic Program
Python basic Program
 
week-17x
week-17xweek-17x
week-17x
 
C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5
 
Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
1346
13461346
1346
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
 
Qprgs
QprgsQprgs
Qprgs
 
Luhn sh
Luhn shLuhn sh
Luhn sh
 
Functional Programming on Android: is it possible?
Functional Programming on Android: is it possible?Functional Programming on Android: is it possible?
Functional Programming on Android: is it possible?
 
CalculateLoanPayments
CalculateLoanPaymentsCalculateLoanPayments
CalculateLoanPayments
 

Similar to Stack ADT Implementation and Applications

DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEswathirajstar
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applicationsAhsan Mansiv
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxShivam Kumar
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
Project of data structure
Project of data structureProject of data structure
Project of data structureUmme habiba
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureYaksh Jethva
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptxSajalFayyaz
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxprakashvs7
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
stack and queue array implementation, java.
stack and queue array implementation, java.stack and queue array implementation, java.
stack and queue array implementation, java.CIIT Atd.
 

Similar to Stack ADT Implementation and Applications (20)

DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
04 stacks
04 stacks04 stacks
04 stacks
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Stack
StackStack
Stack
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
 
STACK1.pptx
STACK1.pptxSTACK1.pptx
STACK1.pptx
 
Chapter 4 stack
Chapter 4 stackChapter 4 stack
Chapter 4 stack
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
Stack
StackStack
Stack
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Stacks
StacksStacks
Stacks
 
stack and queue array implementation, java.
stack and queue array implementation, java.stack and queue array implementation, java.
stack and queue array implementation, java.
 

More from MythiliMurugan3

More from MythiliMurugan3 (9)

DS - Quick Sort
DS - Quick SortDS - Quick Sort
DS - Quick Sort
 
DS - Graph Traversal
DS - Graph TraversalDS - Graph Traversal
DS - Graph Traversal
 
DS - BST
DS - BSTDS - BST
DS - BST
 
DS - Application of List
DS - Application of ListDS - Application of List
DS - Application of List
 
DBMS - Relational Algebra
DBMS - Relational AlgebraDBMS - Relational Algebra
DBMS - Relational Algebra
 
DBMS - Distributed Databases
DBMS - Distributed DatabasesDBMS - Distributed Databases
DBMS - Distributed Databases
 
DBMS - RAID
DBMS - RAIDDBMS - RAID
DBMS - RAID
 
DBMS - Transactions
DBMS - TransactionsDBMS - Transactions
DBMS - Transactions
 
DBMS - ER Model
DBMS - ER ModelDBMS - ER Model
DBMS - ER Model
 

Recently uploaded

247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Recently uploaded (20)

247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

Stack ADT Implementation and Applications

  • 1. STACK ADT: • Stack is a linear data structure in which the insertion and deletion operations are performed at only one end. • In a stack, adding and removing of elements are performed at a single position which is known as "top". • In stack, the insertion and deletion operations are performed based on LIFO (Last In First Out) & FILO (First In Last Out) principle.
  • 2. • In a stack, the insertion operation is performed using a function called "push" and deletion operation is performed using a function called "pop". Operations on a Stack • The following operations are performed on the stack. 1. Push (To insert an element on to the stack) 2. Pop (To delete an element from the stack) 3. Display (To display elements of the stack)
  • 3. • Stack data structure can be implemented in two ways. They are as follows. 1. Using Array 2. Using Linked List • When a stack is implemented using an array, that stack can organize an only limited number of elements. • When a stack is implemented using a linked list, that stack can organize an unlimited number of elements.
  • 4. Implementation of Stack using Array: #include<stdio.h> #include<conio.h> #define SIZE 10 void push(int); void pop(); void display(); int stack[SIZE], top = -1;
  • 5. void main() { int value, choice; clrscr(); while(1) { printf("nn***** MENU *****n"); printf("1.Push 2.Pop 3.Display 4.Exit"); printf("nEnter your choice: "); scanf("%d",&choice);
  • 6. switch(choice) { case 1: printf("Enter the value to insert: "); scanf("%d",&value); push(value); break; case 2: pop(); break; case 3: display(); break; case 4: exit(0); default: printf("nWrong selection!"); } } }
  • 7. void push(int value) { if(top == SIZE-1) printf("nStack is Full!"); else { top++; stack[top] = value; printf("nInsertion success!!!"); } }
  • 8. void pop() { if(top == -1) printf("nStack is Empty!"); else { printf("nDeleted : %d", stack[top]); top--; } }
  • 9. void display() { if(top == -1) printf("nStack is Empty!!!"); else { int i; printf("nStack elements are:n"); for(i=top; i>=0; i--) printf("%dn",stack[i]); } }
  • 10. Implementation of Stack using Linked List: #include<stdio.h> #include<conio.h> struct node { int data; struct node *next; }*top; void push(); void pop(); void display();
  • 11. void main() { int choice; clrscr(); while(1) { printf("nn***** MENU *****n"); printf("1.Push 2.Pop 3.Display 4.Exit"); printf("nEnter your choice: "); scanf("%d",&choice);
  • 12. switch(choice) { case 1: push(); break; case 2: pop(); break; case 3: display(); break; case 4: exit(0); default: printf("nWrong selection!"); } } }
  • 13. void push () { int val; struct node *new =(struct node*)malloc(sizeof (struct node)); printf("Enter the value"); scanf("%d",&val); if(top == NULL) { new->data = val; new->next = NULL;
  • 15. void pop() { struct node *temp=top; if (temp== NULL) printf("Underflow"); else { printf(“Deleted element %d”,temp->data); top = temp->next; free(temp); } }
  • 16. void display() { struct node * temp =top; if(temp == NULL) printf("Stack is emptyn"); else { printf("Printing Stack elements n");
  • 18. Application of Stack: • Evaluating arithmetic expression • Balancing the symbols • Towers of Hanoi • Function calls • 8 Queen problem