Presentation5
Presentation5
PRESENTING BY
DEEKSHA BHVAVANI S
Stacks
Introduction
A stack is a linear data structure that follows the Last-In-First-Out
(LIFO) principle, meaning the last element added is the first one to
be removed
Operations
1. Push operation
2. Pop operation
1. Push: Add an element to the top of the stack
Steps
1. Check if the stack is full
2. Allocate memory for the new element.
3. Add the new element to the top of the stack
4. Update the stack pointerto point to the new element.
Example: Initial Stack: [1, 2, 3]
Push Element: 4
Resulting Stack: [1, 2, 3, 4]
2. Pop: Remove the top element from the stack
Steps:1. Check if the stack is empty.
2. Store the top element in a temporary variable (optional)
3. Remove the top element from the stack.
4. Update the stack pointer (top index) to point to the previous element.
Example
Initial Stack: [1, 2, 3, 4]
Popped Element: 4
Resulting Stack: [1, 2, 3]
Applications of stacks
A real-world example of a stack is a pile of books, plates, or money,
where yo u can only add or remove items from the top.
Introduction To Queue
A queue is open at both ends. One end is provided for the insertion
of data and the other end for the deletion of data.
A queue being an Abstract Data Structure provides the following operations for manipulation on the
data elements:
•isEmpty(): To check if the queue is empty
•isFull(): To check whether the queue is full or not
•dequeue(): Removes the element from the frontal side of the queue
•enqueue(): It inserts elements to the end of the queue
•Front: Pointer element responsible for fetching the first element from the queue
•Rear: Pointer element responsible for fetching the last element from the queue