I have been given a task writing a postfix calculator. I know how to do it using a stack, but that's the catch. I was told to do with recursion and no stack. I busted my *** off trying to figure this out but I'm running short of time and I could really use your help \ tips.
thanks ahead.
RPN (postfix calculator)
Started by butrus, Mar 18 2008 09:27 PM
2 replies to this topic
#1
Posted 18 March 2008 - 09:27 PM
|
|
|
#2
Posted 19 March 2008 - 07:35 AM
I suspect that "by recursion" it means something like the following:
float process(string rpn_string)
{
string operator = //peel off operator
string param1 = //peel out first param string
string param2 = //peel out second param string
result = process(param1) operator process(param2)
}
#3
Posted 22 March 2008 - 01:26 AM
It is nearly the same. When you use a stack, you musst manage all the operations by your self. When you are using recursion, than the operating system manages your stack operations for you.
The operating system puts all function calls on a stack.
So you allready have a stack you can use.
The stack of the operating system contains the hole function. So your function must manage the push and pop operations like the code example above.
Your stack in a non recursive function only contains what you pushed in (e.g. a string).
The operating system puts all function calls on a stack.
So you allready have a stack you can use.
The stack of the operating system contains the hole function. So your function must manage the push and pop operations like the code example above.
Your stack in a non recursive function only contains what you pushed in (e.g. a string).
Edited by nutario, 22 March 2008 - 01:28 AM.


Sign In
Create Account

Back to top









