0% found this document useful (0 votes)
26 views3 pages

Stack Nahid Update

The document describes writing a program to evaluate the value of a postfix expression using a stack. It provides an introduction, objective, algorithm, code, output, debugging steps, limitations, and conclusion. The program uses a stack to store operands and applies operators to pop operands and push results.

Uploaded by

temp.trans.nayan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Stack Nahid Update

The document describes writing a program to evaluate the value of a postfix expression using a stack. It provides an introduction, objective, algorithm, code, output, debugging steps, limitations, and conclusion. The program uses a stack to store operands and applies operators to pop operands and push results.

Uploaded by

temp.trans.nayan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Fall, Year:2023), B.Sc. in CSE (Evening)

Course Title: Data Structure Lab


Course Code: CSE 106
Section: 223 EA
Lab Report No: 01
Lab Experiment Name: Write a program to evaluate value of a postfix expression using stack.

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

Marks: …………………………………. Signature: ................................

Comments: ............................. Date: ........................................


Introduction
In the data structure field stack is an important concept for last in fast out (LIFO). In this report
I will write an algorithm and a c program to evaluate the value of a postfix expression using stack.

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.

You might also like