0% found this document useful (0 votes)
56 views1 page

CPS 162 Program 4 Postfix

This document provides instructions for a computer science program assignment. Students are asked to write a program that evaluates postfix expressions using a stack. The program will accept a postfix expression as a string input from the user. It will use a linked list stack to push operand digits and pop operands to evaluate operators, pushing results back to the stack. The program allows multiple expressions to be evaluated, performing integer calculations.

Uploaded by

SukuratKareem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views1 page

CPS 162 Program 4 Postfix

This document provides instructions for a computer science program assignment. Students are asked to write a program that evaluates postfix expressions using a stack. The program will accept a postfix expression as a string input from the user. It will use a linked list stack to push operand digits and pop operands to evaluate operators, pushing results back to the stack. The program allows multiple expressions to be evaluated, performing integer calculations.

Uploaded by

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

HACC Harrisburg Area Community College

CPS 162 Computer Science II

Fahringer
Program #4

20 points

Due: September 24th

Task: Evaluate a postfix expression using a stack. See Problem #12, pg. 387, in the
Nyhoff textbook.
Input: The user will provide a postfix expression consisting of single-digit whole
numbers and single-char operators (+, -, *, and /). The input should be accepted as a
string.
Processing: Use a linked list stack implementation for the program. Only numbers
will be stored in the stack. When a digit is read from the input string, it will be pushed
onto the stack. When an operator is read from the string, two numbers will be popped
from the stack and the operator will be used to evaluate them; then the result will be
pushed back onto the stack.
Assume that only valid postfix expressions will be entered, so extensive data validation
is not needed. Calculations will be done on the numbers as integers. Permit the user to
enter multiple expressions for evaluation.
Output: As specified by Problem #12, pg. 387.

Sample expressions:
infix:

postfix:

result:

(2 + 7 ) * (3 - 6)

27+36-*

-27

3 - 4 - 1 + (5 / 2)

34-1-52/+

You might also like