Group 3 Stack
Group 3 Stack
STAC
K
1
Click to edit Master title style
What is Stack?
A stack is a fundamental data structure that follows the Last-In-First-
Out (LIFO) principle. It represents a collection of elements where the
last element added is the first one to be removed. Stacks are widely
used in computer science and programming due to their simplicity
and efficiency. They are used in various applications such as
expression evaluation, function call stack management, undo
operations, and more. In this guide, we will explore the concept of
stacks, stack operations (push, pop, peek), stack implementation
using arrays and linked lists, as well as applications and use cases of
stacks in the C# programming language.
2 2
Click to edit Master title style
Introduction to
Stack
A stack is a linear data structure that stores elements in a
particular order. It follows the LIFO (Last-In-First-Out) principle,
meaning that the last element added to the stack is the first one
to be removed. Stacks have two primary operations: push
(adding an element to the top of the stack) and pop
(removing the topmost element from the stack).
Additional operations such as peek (viewing the topmost
element without removing it) and checking for empty or full
conditions are also commonly supported.
3 3
Click to edit Master title
Stack Operations (Push, style Pop, Peek)
Stacks support the following operations:
• Push
The push operation adds an element to the top of the stack. The new
element becomes the topmost element in the stack.
• Pop
The pop operation removes the topmost element from the stack. After the
removal, the next element becomes the new top of the stack.
• Peek
The peek operation allows you to view the topmost element of the stack
without removing it. It is useful for inspecting the element or performing 4 4
Click to edit Master title style
Output
:
7 7
Here's an example of an array-based stack
Click to edit Master title style
implementation in C#:
Output
:
• Function Call Stack: Stacks manage function calls and their local variables, ensuring
proper execution and handling of nested function calls.
• Undo Operations: Stacks are used to implement undo functionality in text editors,
software applications, and interactive environments.
• Backtracking: Stacks are utilized in algorithms that require backtracking, such as maze-
solving and depth-first search.
References:
•Stack (abstract data type) - Wikipedia
•Data Structures and Algorithms in C 10
10
Click to edit Master title style
Thank
You!!!
11