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@4:b4c8aee2ecad, 2015-06-27 (annotated)
- Committer:
- okano
- Date:
- Sat Jun 27 01:21:34 2015 +0000
- Revision:
- 4:b4c8aee2ecad
- Parent:
- 3:4ef74510cc5b
tweaked for better display
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| okano | 2:0e96f4495b43 | 1 | #include "mbed.h" |
| okano | 2:0e96f4495b43 | 2 | #include "calc.h" |
| okano | 2:0e96f4495b43 | 3 | |
| okano | 2:0e96f4495b43 | 4 | #define MAXVAL 100 |
| okano | 2:0e96f4495b43 | 5 | |
| okano | 2:0e96f4495b43 | 6 | int sp = 0; |
| okano | 2:0e96f4495b43 | 7 | double val[ MAXVAL ]; |
| okano | 2:0e96f4495b43 | 8 | |
| okano | 2:0e96f4495b43 | 9 | void push( double f ) |
| okano | 2:0e96f4495b43 | 10 | { |
| okano | 2:0e96f4495b43 | 11 | if ( sp < MAXVAL ) |
| okano | 2:0e96f4495b43 | 12 | val[ sp++ ] = f; |
| okano | 2:0e96f4495b43 | 13 | else |
| okano | 2:0e96f4495b43 | 14 | printf( "error: stack full, can't push %g\n", f ); |
| okano | 2:0e96f4495b43 | 15 | } |
| okano | 2:0e96f4495b43 | 16 | |
| okano | 2:0e96f4495b43 | 17 | |
| okano | 2:0e96f4495b43 | 18 | double pop( void ) |
| okano | 2:0e96f4495b43 | 19 | { |
| okano | 2:0e96f4495b43 | 20 | if ( sp > 0 ) |
| okano | 2:0e96f4495b43 | 21 | return val[ --sp ]; |
| okano | 2:0e96f4495b43 | 22 | else { |
| okano | 2:0e96f4495b43 | 23 | printf( "error: stack empty\n" ); |
| okano | 2:0e96f4495b43 | 24 | return 0.0; |
| okano | 2:0e96f4495b43 | 25 | } |
| okano | 2:0e96f4495b43 | 26 | } |
| okano | 3:4ef74510cc5b | 27 | |
| okano | 3:4ef74510cc5b | 28 | void show_stack( void ) |
| okano | 3:4ef74510cc5b | 29 | { |
| okano | 3:4ef74510cc5b | 30 | for ( int i = 0; i < sp; i++ ) |
| okano | 4:b4c8aee2ecad | 31 | printf( "%3d: %f\n", ((sp - 1) - i), val[ i ] ); |
| okano | 3:4ef74510cc5b | 32 | } |