What Is A Stack
What Is A Stack
operations
Presented By : Ali Hamza
(Mis Id:39369)
Department Of Computer Science
(Date 21/05/2024)
Push Pop
Adding a new element to the top of Removing the top element from the
the stack, increasing the stack size by stack, decreasing the stack size by
one. one.
Peek Is Full
Accessing the top element of the Checking if the stack has reached its
stack without removing it. maximum capacity.
Push Operation
Add Element
To push an element onto the stack, add the new element to the top of the
stack, increasing the stack size by one.
Update Top
The new element becomes the new top of the stack, and all other elements
remain in their original order below it.
Increment Size
The size of the stack is incremented by one to reflect the addition of the new element.
Pop Operation
Update Top
2
The element below the removed one now becomes the
new top of the stack.
Decrement Size
The pop operation in a stack removes the top-most element, making the element below it
the new top of the stack. This reduces the size of the stack by one, maintaining the Last-In-
First-Out (LIFO) principle.
Peek Operation
2 No Changes to Stack
Peeking does not modify the stack - the size and order of elements remain
unchanged.
Check Capacity
1 Determine if the stack has reached its maximum size.
Return True/False
Prevent Overflow
3 Helps avoid adding more elements than
the stack can hold.
The is full operation is a crucial check in stack data structures. It allows you to determine if
the stack has reached its maximum capacity, preventing the addition of new elements that
would exceed the allotted memory. By returning a boolean value, this operation informs the
program whether the stack is currently full or has available space to accommodate new push
operations.
Is Empty Operation
Check Size
1
Determine if the stack is currently empty.
Return True/False
2 The operation returns a boolean value indicating if the
stack is empty.
Avoid Underflow
3
Helps prevent attempting to pop from
an empty stack.
The is empty operation is an essential check in stack data structures. It allows you to quickly
determine if the stack currently contains any elements or if it is in an empty state. By
returning a boolean value, this operation informs the program whether the stack can safely
perform pop or other operations without causing an underflow error.
Stack ADT (Abstract Data Type)