?
2010-04-26 15:01:50 UTC
#include
#include
#define MAX_STACK_SIZE 15
struct stack
{
int currentStackSize;
double currentStackItems[ MAX_STACK_SIZE ];
};
struct stack numbers; /* Stack currently in use by program */
void push( double ); /* Adds a number to the top of the stack */
double pop(); /* Removes a number from the top of the stack */
int main( void )
{
double input;
int counter = 0;
do
{
scanf( "%lf", &input );
if (input>0) push( input );
else if (input==0) pop();
else
break;
counter++;
}
while( counter < 15 );
printf( "Done reading\n" );
counter = 0;
do
{
printf( "Saved: %.2lf\n", pop() );
counter++;
} while ( counter < 15 );
}
void push( double input )
{
if ( numbers.currentStackSize >= MAX_STACK_SIZE ) return;
numbers.currentStackItems[ numbers.currentStackSize ] = input;
numbers.currentStackSize++;
}
double pop()
{
if ( numbers.currentStackSize < 1 ) return 0.0;
numbers.currentStackSize--;
return numbers.currentStackItems[ numbers.currentStackSize ];
}