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

More Related Content

What's hot (19)

Avl tree
Avl treeAvl tree
Avl tree
loyola ICAM college of engineering and technology
 
Stack1
Stack1Stack1
Stack1
Iqrazb
 
Array imp of list
Array imp of listArray imp of list
Array imp of list
Elavarasi K
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Er. Ganesh Ram Suwal
 
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
Grokking VN
 
New microsoft word document
New microsoft word documentNew microsoft word document
New microsoft word document
Abhishek 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 Program
nuripatidar
 
week-17x
week-17xweek-17x
week-17x
KITE www.kitecolleges.com
 
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
Rumman 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 8
Rumman Ansari
 
1346
13461346
1346
VINAY KUMAR KATURI
 
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 4
Rumman Ansari
 
Qprgs
QprgsQprgs
Qprgs
Ssankett Negi
 
Luhn sh
Luhn shLuhn sh
Luhn sh
Ben Pope
 
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
 
CalculateLoanPayments
CalculateLoanPaymentsCalculateLoanPayments
CalculateLoanPayments
William Rutherford
 
Stack1
Stack1Stack1
Stack1
Iqrazb
 
Array imp of list
Array imp of listArray imp of list
Array imp of list
Elavarasi 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 javascript
Grokking VN
 
New microsoft word document
New microsoft word documentNew microsoft word document
New microsoft word document
Abhishek 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 Program
nuripatidar
 
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
Rumman 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 8
Rumman 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 4
Rumman 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
 

Similar to CS8391-Data Structures Unit 2 (20)

DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
swathirajstar
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
Ahsan Mansiv
 
STACKS implimentarions AND stack applications .pptx
STACKS implimentarions AND stack applications .pptxSTACKS implimentarions AND stack applications .pptx
STACKS implimentarions AND stack applications .pptx
Dr. Amna Mohamed
 
04 stacks
04 stacks04 stacks
04 stacks
Rajan Gautam
 
6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx
RahulRaj493025
 
Stack-data-structure.ppsxErwewwwrrterewewew
Stack-data-structure.ppsxErwewwwrrterewewewStack-data-structure.ppsxErwewwwrrterewewew
Stack-data-structure.ppsxErwewwwrrterewewew
RamaKrishnaErroju
 
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
RAtna29
 
Stack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptxStack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptx
yukti266975
 
Stack
StackStack
Stack
Amrutha Rajan
 
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
Shivam Kumar
 
STACK1.pptx
STACK1.pptxSTACK1.pptx
STACK1.pptx
MouDhara1
 
Chapter 4 stack
Chapter 4 stackChapter 4 stack
Chapter 4 stack
jadhav_priti
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
Sheikh Monirul Hasan
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
Data Structures and algorithms using c .ppt
Data Structures and algorithms using c .pptData Structures and algorithms using c .ppt
Data Structures and algorithms using c .ppt
RaviKumarChavali1
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
EktaVaswani2
 
Stack data structures with definition and code
Stack data structures with definition and codeStack data structures with definition and code
Stack data structures with definition and code
bansidharj11
 
DSA_Unit3_ Stacks and Queues using array (1).pptx
DSA_Unit3_ Stacks and Queues  using array  (1).pptxDSA_Unit3_ Stacks and Queues  using array  (1).pptx
DSA_Unit3_ Stacks and Queues using array (1).pptx
nandinigujarathi9
 
introduction of the Stacks and Queues.pptx
introduction of the  Stacks and Queues.pptxintroduction of the  Stacks and Queues.pptx
introduction of the Stacks and Queues.pptx
kavitashingi123
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
swathirajstar
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
Ahsan Mansiv
 
STACKS implimentarions AND stack applications .pptx
STACKS implimentarions AND stack applications .pptxSTACKS implimentarions AND stack applications .pptx
STACKS implimentarions AND stack applications .pptx
Dr. Amna Mohamed
 
6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx
RahulRaj493025
 
Stack-data-structure.ppsxErwewwwrrterewewew
Stack-data-structure.ppsxErwewwwrrterewewewStack-data-structure.ppsxErwewwwrrterewewew
Stack-data-structure.ppsxErwewwwrrterewewew
RamaKrishnaErroju
 
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
RAtna29
 
Stack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptxStack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptx
yukti266975
 
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
Shivam Kumar
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
Data Structures and algorithms using c .ppt
Data Structures and algorithms using c .pptData Structures and algorithms using c .ppt
Data Structures and algorithms using c .ppt
RaviKumarChavali1
 
Stack data structures with definition and code
Stack data structures with definition and codeStack data structures with definition and code
Stack data structures with definition and code
bansidharj11
 
DSA_Unit3_ Stacks and Queues using array (1).pptx
DSA_Unit3_ Stacks and Queues  using array  (1).pptxDSA_Unit3_ Stacks and Queues  using array  (1).pptx
DSA_Unit3_ Stacks and Queues using array (1).pptx
nandinigujarathi9
 
introduction of the Stacks and Queues.pptx
introduction of the  Stacks and Queues.pptxintroduction of the  Stacks and Queues.pptx
introduction of the Stacks and Queues.pptx
kavitashingi123
 
Ad

More from SIMONTHOMAS S (20)

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1
SIMONTHOMAS S
 
Mg6088 spm unit-5
Mg6088 spm unit-5Mg6088 spm unit-5
Mg6088 spm unit-5
SIMONTHOMAS S
 
Mg6088 spm unit-4
Mg6088 spm unit-4Mg6088 spm unit-4
Mg6088 spm unit-4
SIMONTHOMAS S
 
Mg6088 spm unit-3
Mg6088 spm unit-3Mg6088 spm unit-3
Mg6088 spm unit-3
SIMONTHOMAS S
 
Mg6088 spm unit-2
Mg6088 spm unit-2Mg6088 spm unit-2
Mg6088 spm unit-2
SIMONTHOMAS S
 
Mg6088 spm unit-1
Mg6088 spm unit-1Mg6088 spm unit-1
Mg6088 spm unit-1
SIMONTHOMAS S
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5
SIMONTHOMAS S
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4
SIMONTHOMAS S
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3
SIMONTHOMAS S
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2
SIMONTHOMAS S
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
SIMONTHOMAS S
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5
SIMONTHOMAS S
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4
SIMONTHOMAS S
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3
SIMONTHOMAS S
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
SIMONTHOMAS S
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1
SIMONTHOMAS S
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5
SIMONTHOMAS S
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4
SIMONTHOMAS S
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3
SIMONTHOMAS S
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2
SIMONTHOMAS S
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
SIMONTHOMAS S
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5
SIMONTHOMAS S
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4
SIMONTHOMAS S
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3
SIMONTHOMAS S
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
SIMONTHOMAS S
 
Ad

Recently uploaded (20)

Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Journal of Soft Computing in Civil Engineering
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
Reflections on Morality, Philosophy, and History
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
Empowering Electric Vehicle Charging Infrastructure with Renewable Energy Int...
AI Publications
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 

CS8391-Data Structures Unit 2

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