Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stack.cpp
- Committer:
- okano
- Date:
- 2015-06-26
- Revision:
- 3:4ef74510cc5b
- Parent:
- 2:0e96f4495b43
- Child:
- 4:b4c8aee2ecad
File content as of revision 3:4ef74510cc5b:
#include "mbed.h"
#include "calc.h"
#define MAXVAL 100
int sp = 0;
double val[ MAXVAL ];
void push( double f )
{
if ( sp < MAXVAL )
val[ sp++ ] = f;
else
printf( "error: stack full, can't push %g\n", f );
}
double pop( void )
{
if ( sp > 0 )
return val[ --sp ];
else {
printf( "error: stack empty\n" );
return 0.0;
}
}
void show_stack( void )
{
for ( int i = 0; i < sp; i++ )
printf( "%3d: %f\n", i, val[ i ] );
}