Post Reply 
Stack algorithm
07-13-2016, 09:54 AM (This post was last modified: 07-13-2016 09:55 AM by Dieter.)
Post: #5
RE: Stack algorithm
(07-13-2016 02:28 AM)Dwight Sturrock Wrote:  Here are a few stack functions I wrote as part of a larger C++ program.

About 20 years ago I did something similar with an RPN calculator written in Pascal.

(07-13-2016 02:28 AM)Dwight Sturrock Wrote:  The function names and comments are fairly self explanatory. My approach was fairly straightforward. I discovered there are many special cases that have to be accounted for when emulating RPN stack dynamics.

It's not that complicated. Essentially it all boils down to the question whether stacklift is enabled or not. So a simple boolean variable "stacklift" will do. It is true after an operation or function call (except Σ+/Σ–) and false after ENTER and CLX. If a digit key (including dot/comma, CHS and EEX) is pressed, start a new number entry (resp. change sign) if stacklift is true resp. append to the current entry if not. Essentially, that's all you have to handle.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Stack algorithm - deetee - 07-12-2016, 12:36 PM
RE: Stack algorithm - Namir - 07-12-2016, 04:32 PM
RE: Stack algorithm - Paul Dale - 07-12-2016, 09:55 PM
RE: Stack algorithm - Dwight Sturrock - 07-13-2016, 02:28 AM
RE: Stack algorithm - Dieter - 07-13-2016 09:54 AM
RE: Stack algorithm - deetee - 07-13-2016, 02:13 PM



User(s) browsing this thread: 1 Guest(s)