Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help on my Stack program

Status
Not open for further replies.

T1234

Programmer
Sep 8, 2002
1
GB
how can i translate this to C program?

FOR each character (say ch) in the valid expression DO
if ch is a digit
if stack is not full
number = ch-48
push the character's number into the stack
else
print stack overflow message and exit the program
else if current_ch is one of the operators
if stack has less than 2 numbers in it {
print error message, and exit
else
pop 2 numbers from stack
Call compute two numbers with the operator
push result back into stack
end if
end if

END-FOR

On exit from the above FOR loop:
if stack is empty OR has more than 1 number in it
print error message and exit
else
pop final result from stack
print final result
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top