Stack Nahid Update
Stack Nahid Update
Student Details
Name ID
MD NAHIDUL ISLAM NAYAN 223015019
Lab Date: 13/10/2023
Submission Date: 20/10/2023
Course Teacher’s Name: Dr. Md. Mostafijur Rahman
[For Teachers use only: Don’t Write Anything inside this box]
Lab Report Status
Objective
To apply the stack on evaluate postfix expression we must need a stack array to store operant
and, we need a postfix array to store input expression. Scan the postfix expression from left to
right. If the current character is an operand, push it onto the stack. If the current character is an
operator, pop the top two operands off the stack and apply the operator to them. Push the
result back onto the stack.
Algorithm
Step 1: Input: postfix
Step 2: create a stack using array
Step 3: Travers the postfix (for, while. Do-while: loops)
Step 4: if scanned character is operand, then push it to the stack
Step 5: if scanned character is operator, then pop two characters from the stack and apply the
operator using switch-case or if-else
Step 6: push new character to the stack
Step 7: repeated the step until the calculation is complete
Step 8: Print: the stack
Code: https://github.com/mnin-nahid/DSA-using-C/blob/main/stack/postfix-calculation-using-stack.c
Output
Debug and Testing
• Use VS Code to debug this program.
• Run program with simple inputs.
Limitation
• This program can handle a small number of characters.
• It only can handle summation, subtraction, multiplication and division
• This program doesn't calculate the power.
Conclusion
In this experiment we learn how to store and manipulate user input using stack. The concept of
stack is last in fast out in sort LIFO. Here, we must be careful that we are accessing only the last
memory address on a stack.