GROUP 3
PRESENTATION
Group 3 Reporters
• Balbin, Jrob Francis G.
• Bernales, Lance Christian
• De Sagun, Lorraine Frances
• Navos, Nathan East
• Opiz, Josef Andrei
Basic Data
Structure Stacks
Basic Data Structure Stacks
Stacks Operations
Pop, Push, Top
Parsing and Evaluation of Arithmetic
Expression using stacks
Postfix and Infix Notation
Sample Programs
ICE BREAKER
LET’S GOOO!!!!
ICE BREAKER
swap two variables without using a
temporary variable, relying on basic
arithmetic operations (addition and
subtraction).
LESSON PROPER
Defining Stacks
Stack Operations
Stack Operations
A stack is a linear data structure that
follows the Last In - First Out (LIFO)
principle, where the last element added to
the stack is the first one to be removed.
Two primary operations:
PUSH Adds an element to the top of the stack
POP Removes the top element
Basic operations
stack<type> stackName()
Syntax to create a Stack
Example
stack<string> cars;
Basic operations
.push()
To add elements to the stack
Basic operations
Example
stack<string> cars;
stack<string> cars = {"Volvo",
cars.push("Volvo"); "BMW", "Ford", "Mazda"};
cars.push("BMW");
cars.push("Ford");
cars.push("Mazda");
Basic operations
.top()
returns the top element on the stack.
Example
cout << cars.top();
Basic operations
.pop()
To remove an element from the stack.
Example: stack<string> cars;
cars.push("Volvo");
cars.push("BMW");
cars.push("Ford");
cars.push("Mazda");
cars.pop();
cout << cars.top();
Basic operations
.size()
To find out how many elements a stack
has.
Example:
cout << cars.size();
Key Characteristics
LIFO stands for Last in, First Out.
to use a stack, you have to include
the <stack> header file:
The syntax to create a Stack:
stack<type> stackName()
THE THE THE
POP, PUSH, TOP
Remember
A stack is a data structure that
can hold many elements.
Pop, Push, Top
In a stack data structure, the pop, push,
and top functions are fundamental
operations used to manage elements
based on the Last In, First Out (LIFO)
principle.
These are basic operations we can do on a stack
Pop Removes and returns the top element
from the stack.
Push Adds a new element on the stack.
Top Returns the top element on the stack.
Other basic operations includes
Empty: Checks if the stack is empty.
Size: Finds the number of elements in the stack
Some syntax for using stacks
<stack>: The library inclusion for using stacks
stack<type> stackName: The syntax for declaration of stack
stackName.operation(); : The syntax for using the operation
Sample
Program
Sample
Program
Parsing and Evaluation
of Arithmetic
Expressions using
Stacks
Parsing and Evaluation of Arithmetic
Expressions using Stacks
The process is divided into two parts;
Parsing is a process of analyzing and breaking down
strings of symbols into tokens.
Tokenization refers to the broken down inputs and
grouped based on its type.
Postfix & Infix Notation
Postfix & Infix Notation
Postfix and Infix notations are different
ways of writing mathematical expressions.
Understanding these notations is essential
in computer science, especially when
working with stacks in data structures.
Postfix & Infix Notation
Infix Notation - Is the standard way of writing mathematical
expressions, where operators are placed between operands.
Example:
A + B, (A x B) - C
Postfix Notation - In postfix notation, operators are placed after
their operands.
AB+, ABCx-
Postfix & Infix Notation
Operator Priority/Precedence
Exponentation (^) 1st (Highest)
Multiplication (*)
Division (/)
2nd
Addition (+)
Subtraction (-)
3rd (Lowest)
Postfix & Infix Notation
Note; Expressions within the
parentheses are always first priority.
Postfix & Infix Notation
Operator
Infix: A+B*C-D/E
Operand
Operator
Postfix: ABC*+DE/-
Operand
Postfix & Infix Notation
Operator
Infix: 5+3*2-8/4 =9
Operand
Operator
Postfix: 532*+84/- =9
Operand
Postfix & Infix Notation
Infix Expression
5+3*2-8/4 = 9
Postfix Evaluation
Step 1: 5 3 2 * + 8 4 / - = 56+84/-
Step 2: 5 6 + 8 4 / - = 56+2-
Step 3: 5 6 + 2 - = 11 2 -
Step 4: 11 2 - = 9
Sample
Program
Conclusion
Thank you
for listening!
QUIZ TIME
SEATWORK
LAB ACT 3
GROUP 3
PRESENTATION