Post Reply 
Stack algorithm
07-13-2016, 02:28 AM
Post: #4
RE: Stack algorithm
Here are a few stack functions I wrote as part of a larger C++ program. 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.

PHP Code:
void enter_pressed(bool *enter_was_pressed_)
    {
    
t=z;
    
z=y;
    
y=x;
    
//x=x
    
write_stack();
    *
enter_was_pressed_=1;
    
//after an enter I should be able to overwrite x
    


PHP Code:
void add_pressed(bool *a_function_was_executed_bool *decimal_fraction_)
    {
    
//z=z
    
x=y+x;    //perform math first
    
y=z;
    
z=t;
    *
a_function_was_executed_=1;    //after a function is executed, stack lift must be enabled
    
*decimal_fraction_=0;            //since a function has been executed, we are back on the left side of the decimal point
    
write_stack();
    } 

PHP Code:
void space_pressed (bool *decimal_fraction_bool *a_function_was_executed_bool *enter_was_pressed_bool *decimal_point_just_pressed_)    
    
//space is the CLEAR STACK key
    
{
        
t=0;
        
z=0;
        
y=0;
        
x=0;
        
w=0;
        
place_value=10;
        *
decimal_fraction_=0;            //clear all flags:
        
*a_function_was_executed_=0
        *
enter_was_pressed_=0;
        *
decimal_point_just_pressed_=0;
        
write_stack();
    } 

PHP Code:
void tab_pressed()    //tab is the CHS key
    
{
    
x=x*(-1);
    
write_stack();
    } 

PHP Code:
void roll_up_pressed(bool *a_function_was_executed_)
    {
    
w=t;
    
t=z;
    
z=y;
    
y=x;
    
x=w;
    *
a_function_was_executed_=1;    //rolling the stack requires the a_function_was_executed flag to be set for proper stack lift
    
write_stack();
    } 
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)