SlideShare a Scribd company logo
Stack
Stack is a linear data structure that follows a particular order in
which the operations are performed. The order may be LIFO(Last In
First Out) or FILO(First In Last Out).
•
•
•
•
•
Basic Operations
Following are the basic operations that are supported by the
stack.
Push: Adds an item in the stack. If the stack is full, then it is said
to be an Overflow condition.
Pop: Removes an item from the stack. The items are popped in
the reversed order in which they are pushed. If the stack is empty,
then it is said to be an Underflow condition.
Peek or Top: Returns the top element of the stack.
isEmpty: Returns true if the stack is empty, else false.
isFull – Tests if the stack is full.
Time Complexities of operations on stack
push()
pop()
isEmpty()
isFull()
peek()
Above all take O(1) time. We do not run any loop in any of these
operations.
•
•
•
•
•
•
•
Applications of Stack
Redo-undo features at many places like editors, photoshop.
Forward and backward feature in web browsers
Used in many algorithms like Tower of Hanoi, tree traversals, stock span
problem, histogram problem.
Backtracking is one of the algorithm designing techniques.
In Graph Algorithms like Topological Sorting and Strongly Connected
Components
In Memory management, any modern computer uses a stack as the
primary management for a running purpose. Each program that is running
in a computer system has its own memory allocations
String reversal is also another application of stack.
•
•
Implementation
There are two ways to implement a stack:
Using array
Using linked list
•
•
•
•
Push Operation
The process of putting a new data element onto
stack is known as a Push Operation. Push
operation involves a series of steps −
Step 1 − Checks if the stack is full.
Step 2 − If the stack is full, produces an error
and exit.
Step 3 − If the stack is not full,
increments top to point next empty space.
Step 4 − Adds data element to the stack
location,
where top is pointing.
•
•
•
Pop Operation
Accessing the content while removing it
from the stack, is known as a Pop
Operation.
A Pop operation may involve the
following steps −
Step 1 − Checks if the stack is empty.
Step 2 − If the stack is empty, produces
an error and exit.
Step 3 − If the stack is not empty,
delete the data element at which top is
pointing.

More Related Content

PPTX
The presentation on stack data structure
PPTX
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
PPTX
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
PPTX
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
PPTX
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
PPTX
Stack organization
PPTX
Stack and Queue.pptx
PPTX
The presentation on stack data structure
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
Stack organization
Stack and Queue.pptx

Similar to 4-Stack --------------------------------in C++.pdf (20)

PPT
Stack a Data Structure
PPTX
Stacks in Data Structure
PDF
Stacks-and-Queues.pdf
PPTX
Stack and queue
PPTX
Basic Queue Operation in DataStructure.pptx
PPTX
CD3291 2.5 stack.pptx
PPTX
Chapter 5-stack.pptx
PPT
Difference between stack and queue
PPT
week 7,8,10,11 alll files included from .ppt
PDF
Chapter 4 stack
PPT
The Stack in data structures .ppt
DOCX
Stack - Operations and Applications
PPTX
Unit 3 Stacks and Queues.pptx
PDF
Data structure.pdf
PPTX
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
PPTX
Javascript stack
PPTX
5.-Stacks.pptx
PPTX
Introduction to information about Data Structure.pptx
PDF
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
Stack a Data Structure
Stacks in Data Structure
Stacks-and-Queues.pdf
Stack and queue
Basic Queue Operation in DataStructure.pptx
CD3291 2.5 stack.pptx
Chapter 5-stack.pptx
Difference between stack and queue
week 7,8,10,11 alll files included from .ppt
Chapter 4 stack
The Stack in data structures .ppt
Stack - Operations and Applications
Unit 3 Stacks and Queues.pptx
Data structure.pdf
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
Javascript stack
5.-Stacks.pptx
Introduction to information about Data Structure.pptx
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
Ad

Recently uploaded (20)

PPT
Mechanical Engineering MATERIALS Selection
PDF
Digital Logic Computer Design lecture notes
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
PPT on Performance Review to get promotions
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Project quality management in manufacturing
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
additive manufacturing of ss316l using mig welding
Mechanical Engineering MATERIALS Selection
Digital Logic Computer Design lecture notes
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPT on Performance Review to get promotions
bas. eng. economics group 4 presentation 1.pptx
Project quality management in manufacturing
Internet of Things (IOT) - A guide to understanding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
OOP with Java - Java Introduction (Basics)
Strings in CPP - Strings in C++ are sequences of characters used to store and...
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Lecture Notes Electrical Wiring System Components
Embodied AI: Ushering in the Next Era of Intelligent Systems
Structs to JSON How Go Powers REST APIs.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
additive manufacturing of ss316l using mig welding
Ad

4-Stack --------------------------------in C++.pdf

  • 2. Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
  • 3. • • • • • Basic Operations Following are the basic operations that are supported by the stack. Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow condition. Pop: Removes an item from the stack. The items are popped in the reversed order in which they are pushed. If the stack is empty, then it is said to be an Underflow condition. Peek or Top: Returns the top element of the stack. isEmpty: Returns true if the stack is empty, else false. isFull – Tests if the stack is full.
  • 4. Time Complexities of operations on stack push() pop() isEmpty() isFull() peek() Above all take O(1) time. We do not run any loop in any of these operations.
  • 5. • • • • • • • Applications of Stack Redo-undo features at many places like editors, photoshop. Forward and backward feature in web browsers Used in many algorithms like Tower of Hanoi, tree traversals, stock span problem, histogram problem. Backtracking is one of the algorithm designing techniques. In Graph Algorithms like Topological Sorting and Strongly Connected Components In Memory management, any modern computer uses a stack as the primary management for a running purpose. Each program that is running in a computer system has its own memory allocations String reversal is also another application of stack.
  • 6. • • Implementation There are two ways to implement a stack: Using array Using linked list
  • 7. • • • • Push Operation The process of putting a new data element onto stack is known as a Push Operation. Push operation involves a series of steps − Step 1 − Checks if the stack is full. Step 2 − If the stack is full, produces an error and exit. Step 3 − If the stack is not full, increments top to point next empty space. Step 4 − Adds data element to the stack location, where top is pointing.
  • 8. • • • Pop Operation Accessing the content while removing it from the stack, is known as a Pop Operation. A Pop operation may involve the following steps − Step 1 − Checks if the stack is empty. Step 2 − If the stack is empty, produces an error and exit. Step 3 − If the stack is not empty, delete the data element at which top is pointing.