SlideShare a Scribd company logo
Stack Data Structure By : Imam M Shofi
What is stack? A stack is a limited version of an array.  New elements, or nodes as they are often called, can be added to a stack and removed from a stack only from one end.  Access system a stack is referred to as a LIFO structure (Last-In First-Out) Some illustrations: stack of satay stack of CDs
Stacks operations Push : adds a new node Push(X,S)    add the value X to the TOP of stack Pop : removes a node Pop(S)    removes the TOP node and returns its value IsEmpty : reports whether the stack is empty IsEmpty(S)    report whether the stack S is empty IsFull : reports whether the stack is full IsFull(S)    report whether the stack S is full  Initialize : creates/initializes the stack Initialize(S)    create a new empty stack named S Destroy : deletes the contents of the stack (may be implemented by re-initializing the stack) Destroy(S)    deletes the contents of the stack S
Illustration/example Operation Stack’s contents TOP value 1. Initialiaze(S) <empty> 0 2. Push(‘a’,S) a 1 3. Push(‘b’,S) a b 2 4. Push(‘c’,S) a b c 3 5. Pop(S) a b 2 6. Push(‘d’,S) a b d 3 7. Push(‘e’,S) a b d e 4 8. Pop(S) a b d 3 9. Pop(S) a b 2 10. Pop(S) a 1
Exercise What would the state of the stack be after the following operations: create stack push A onto stack push F onto stack pop item from stack push B onto stack pop item from stack pop item from stack Show the state of the stack and the value of each variable after execution of each of the following statements: A = 5 B = 3 C = 7 (a) create stack push A onto stack push C*C onto stack pop item from stack and store in B push B+A onto stack pop item from stack and store in A pop item from stack and store in B (b) create stack push B onto stack push C onto stack push A onto stack A=B*C push A+C onto stack pop item from stack and store in A pop item from stack and store in B pop item from stack and store in C
Converting between notations INFIX to PREFIX : (A+B) – (C*D) Do the first brace: (A+B), the PREFIX is +AB Do the second brace: (C*D), the PREFIX is *CD The end is operator -:  +AB  -  *CD ,  the PREFIX is -+AB*CD INFIX to POSTFIX : (A+B) – (C*D) Do the first brace: (A+B), the POSTFIX is AB+ Do the second brace: (C*D), the POSTFIX is CD* The end is operator -:  AB+  -  CD* ,  the PREFIX is AB+CD*- PREFIX to INFIX : +/*A B C D Find the first operator: *, take 2 operands before the operator ( A  and  B ), the INFIX is (A*B) Find the second operator: /, take 2 operands before the operator ( A*B  and  C ), the INFIX is ((A*B)/C) Find the third operator: +, take 2 operands before the operator ( ((A*B)/C)  and  D ), the INFIX is ((A*B)/C)+D
Converting between notations(2) PREFIX to POSTFIX : +/*A B C D Find the first operator: *, take 2 operands before the operator ( A  and  B ), the POSTFIX is AB* Find the second operator: /, take 2 operands before the operator ( AB*  and  C ), the POSTFIX is AB*C/ Find the third operator: +, take 2 operands before the operator ( AB*C/  and  D ), the POSTFIX is AB*C/D+ POSTFIX to INFIX : ABCD*/- Find the first operator: *, take 2 operands before the operator ( C  and  D ), the INFIX is (C*D) Find the second operator: /, take 2 operands before the operator ( (C*D)  and  B ), the INFIX is (B/(C*D) Find the third operator: -, take 2 operands before the operator ( (B/(C*D)  and  A ), the INFIX is A – (B/(C*D) POSTFIX to PREFIX : ABCD*/- Find the first operator: *, take 2 operands before the operator ( C  and  D ), the PREFIX is *CD Find the second operator: /, take 2 operands before the operator ( *CD  and  B ), the PREFIX is /B*CD Find the third operator: -, take 2 operands before the operator ( /B*CD  and  A ), the PREFIX is -A /B*CD
Exercise: Converting Convert these INFIX to PREFIX and POSTFIX : A / B – C / D (A + B) ^ 3 – C * D A ^ (B + C) Convert these PREFIX to INFIX and POSTFIX : + – / A B C ^ D E –  + D E / X Y ^ + 2 3 – C D Convert these POSTFIX to INFIX and PREFIX : A B C + –  G H + I J / * A B ^ C D + –

More Related Content

PPT
Stack application
PPT
Stack Operation In Data Structure
PPTX
Application of Stack - Yadraj Meena
PPTX
Stack data structure
PPTX
Stack - Data Structure
PPSX
PPT
03 stacks and_queues_using_arrays
PPTX
Stack and queue
Stack application
Stack Operation In Data Structure
Application of Stack - Yadraj Meena
Stack data structure
Stack - Data Structure
03 stacks and_queues_using_arrays
Stack and queue

What's hot (20)

PPTX
STACKS IN DATASTRUCTURE
PPT
Stacks
PPT
Conversion of Infix To Postfix Expressions
PPT
PPT
PPTX
Stacks in DATA STRUCTURE
PPT
PPTX
Stack and its Applications : Data Structures ADT
PPTX
Stack_Application_Infix_Prefix.pptx
PPSX
Stacks Implementation and Examples
PPTX
Stacks in c++
PPT
Application of Stacks
PPTX
Project of data structure
PPTX
Unit 3 stack
PPTX
Data structure Stack
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPTX
Data structure by Digvijay
PPTX
Stacks in Data Structure
PPTX
Introduction to stack
STACKS IN DATASTRUCTURE
Stacks
Conversion of Infix To Postfix Expressions
Stacks in DATA STRUCTURE
Stack and its Applications : Data Structures ADT
Stack_Application_Infix_Prefix.pptx
Stacks Implementation and Examples
Stacks in c++
Application of Stacks
Project of data structure
Unit 3 stack
Data structure Stack
STACK ( LIFO STRUCTURE) - Data Structure
Data structure by Digvijay
Stacks in Data Structure
Introduction to stack
Ad

Viewers also liked (20)

PPSX
Data Structure (Stack)
PPTX
Stack Data structure
PPT
Stack a Data Structure
PPT
Stack Data Structure & It's Application
PPT
PPT
data structure, stack, stack data structure
PPTX
Stack Data Structre Introduction and source code
PDF
Algoritma dan Pemrograman C++ (Percabangan)
PDF
It 405 materi 2 java dasar
PDF
Viisio based rich picture version 2.0
PDF
Career Hub Rich Picture
PDF
MeTA MSP workshop: Issues and challenges: Rich picture
PDF
Rich_Picture--IA_Manager.220131720
PPT
Program design techniques
PDF
AN UPDATED REVIEW ON THE CONVENTIONAL AND UNCONVENTIONAL RICH PICTURE BUILD...
PDF
CPI Rich Picture
PPTX
Data Structures - Lecture 5 [Stack]
PDF
Linux vs. Windows
PPTX
Linux vs windows
Data Structure (Stack)
Stack Data structure
Stack a Data Structure
Stack Data Structure & It's Application
data structure, stack, stack data structure
Stack Data Structre Introduction and source code
Algoritma dan Pemrograman C++ (Percabangan)
It 405 materi 2 java dasar
Viisio based rich picture version 2.0
Career Hub Rich Picture
MeTA MSP workshop: Issues and challenges: Rich picture
Rich_Picture--IA_Manager.220131720
Program design techniques
AN UPDATED REVIEW ON THE CONVENTIONAL AND UNCONVENTIONAL RICH PICTURE BUILD...
CPI Rich Picture
Data Structures - Lecture 5 [Stack]
Linux vs. Windows
Linux vs windows
Ad

Similar to Stack Data Structure V1.0 (20)

PPTX
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
PPT
Unit 3 stack
PPTX
Implementation of stacks and queues in C
PPT
Stacks.ppt
PPT
Stacks.ppt
PPT
Data Structure and Algorithms Stacks
PDF
PPTX
Stack - Data Structure - Notes
PPTX
Data structures
PPTX
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
PPTX
Lec5-Stack-bukc-28022024-112316am (1) .pptx
PDF
Data Structures And Algorithms(stacks queues)
PDF
Data structures stacks
PPT
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
PPT
computer notes - Data Structures - 6
PPT
Expression evaluation
PPTX
Stack, implementation using array and linked list
PPTX
DS1.pptx
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
Unit 3 stack
Implementation of stacks and queues in C
Stacks.ppt
Stacks.ppt
Data Structure and Algorithms Stacks
Stack - Data Structure - Notes
Data structures
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Data Structures And Algorithms(stacks queues)
Data structures stacks
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
computer notes - Data Structures - 6
Expression evaluation
Stack, implementation using array and linked list
DS1.pptx

More from Zidny Nafan (6)

PPT
Materi 4 Information System Engineering Sim 1223511116853894 8
PPT
Kuliah1 Struktur Data V1.0
PPT
Stack Implementation
PPT
List Data Structure
PPT
Queue Data Structure
PDF
Java Greenfator
Materi 4 Information System Engineering Sim 1223511116853894 8
Kuliah1 Struktur Data V1.0
Stack Implementation
List Data Structure
Queue Data Structure
Java Greenfator

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
sap open course for s4hana steps from ECC to s4
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Spectroscopy.pptx food analysis technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx

Stack Data Structure V1.0

  • 1. Stack Data Structure By : Imam M Shofi
  • 2. What is stack? A stack is a limited version of an array. New elements, or nodes as they are often called, can be added to a stack and removed from a stack only from one end. Access system a stack is referred to as a LIFO structure (Last-In First-Out) Some illustrations: stack of satay stack of CDs
  • 3. Stacks operations Push : adds a new node Push(X,S)  add the value X to the TOP of stack Pop : removes a node Pop(S)  removes the TOP node and returns its value IsEmpty : reports whether the stack is empty IsEmpty(S)  report whether the stack S is empty IsFull : reports whether the stack is full IsFull(S)  report whether the stack S is full Initialize : creates/initializes the stack Initialize(S)  create a new empty stack named S Destroy : deletes the contents of the stack (may be implemented by re-initializing the stack) Destroy(S)  deletes the contents of the stack S
  • 4. Illustration/example Operation Stack’s contents TOP value 1. Initialiaze(S) <empty> 0 2. Push(‘a’,S) a 1 3. Push(‘b’,S) a b 2 4. Push(‘c’,S) a b c 3 5. Pop(S) a b 2 6. Push(‘d’,S) a b d 3 7. Push(‘e’,S) a b d e 4 8. Pop(S) a b d 3 9. Pop(S) a b 2 10. Pop(S) a 1
  • 5. Exercise What would the state of the stack be after the following operations: create stack push A onto stack push F onto stack pop item from stack push B onto stack pop item from stack pop item from stack Show the state of the stack and the value of each variable after execution of each of the following statements: A = 5 B = 3 C = 7 (a) create stack push A onto stack push C*C onto stack pop item from stack and store in B push B+A onto stack pop item from stack and store in A pop item from stack and store in B (b) create stack push B onto stack push C onto stack push A onto stack A=B*C push A+C onto stack pop item from stack and store in A pop item from stack and store in B pop item from stack and store in C
  • 6. Converting between notations INFIX to PREFIX : (A+B) – (C*D) Do the first brace: (A+B), the PREFIX is +AB Do the second brace: (C*D), the PREFIX is *CD The end is operator -: +AB - *CD , the PREFIX is -+AB*CD INFIX to POSTFIX : (A+B) – (C*D) Do the first brace: (A+B), the POSTFIX is AB+ Do the second brace: (C*D), the POSTFIX is CD* The end is operator -: AB+ - CD* , the PREFIX is AB+CD*- PREFIX to INFIX : +/*A B C D Find the first operator: *, take 2 operands before the operator ( A and B ), the INFIX is (A*B) Find the second operator: /, take 2 operands before the operator ( A*B and C ), the INFIX is ((A*B)/C) Find the third operator: +, take 2 operands before the operator ( ((A*B)/C) and D ), the INFIX is ((A*B)/C)+D
  • 7. Converting between notations(2) PREFIX to POSTFIX : +/*A B C D Find the first operator: *, take 2 operands before the operator ( A and B ), the POSTFIX is AB* Find the second operator: /, take 2 operands before the operator ( AB* and C ), the POSTFIX is AB*C/ Find the third operator: +, take 2 operands before the operator ( AB*C/ and D ), the POSTFIX is AB*C/D+ POSTFIX to INFIX : ABCD*/- Find the first operator: *, take 2 operands before the operator ( C and D ), the INFIX is (C*D) Find the second operator: /, take 2 operands before the operator ( (C*D) and B ), the INFIX is (B/(C*D) Find the third operator: -, take 2 operands before the operator ( (B/(C*D) and A ), the INFIX is A – (B/(C*D) POSTFIX to PREFIX : ABCD*/- Find the first operator: *, take 2 operands before the operator ( C and D ), the PREFIX is *CD Find the second operator: /, take 2 operands before the operator ( *CD and B ), the PREFIX is /B*CD Find the third operator: -, take 2 operands before the operator ( /B*CD and A ), the PREFIX is -A /B*CD
  • 8. Exercise: Converting Convert these INFIX to PREFIX and POSTFIX : A / B – C / D (A + B) ^ 3 – C * D A ^ (B + C) Convert these PREFIX to INFIX and POSTFIX : + – / A B C ^ D E – + D E / X Y ^ + 2 3 – C D Convert these POSTFIX to INFIX and PREFIX : A B C + – G H + I J / * A B ^ C D + –