#include
<
assert.h
>
#include < stdio.h >
#if defined(stack_size)
#else
#define stack_size 100
#endif
extern int array[stack_size];
extern int top_element;
int is_empty( void )
{
return top_element == - 1 ;
}
int is_full( void )
{
return top_element == stack_size - 1 ;
}
void push( int value)
{
assert( ! is_full());
top_element += 1 ;
array[top_element] = value;
printf( " top_element = %d top = %d " ,array[top_element],top_element);
}
int top( void )
{
assert( ! is_empty());
return array[top_element] ;
}
void pop( void )
{
assert( ! is_empty());
array[top_element] = 0 ;
top_element -= 1 ;
}
#include < stdio.h >
#if defined(stack_size)
#else
#define stack_size 100
#endif
extern int array[stack_size];
extern int top_element;
int is_empty( void )
{
return top_element == - 1 ;
}
int is_full( void )
{
return top_element == stack_size - 1 ;
}
void push( int value)
{
assert( ! is_full());
top_element += 1 ;
array[top_element] = value;
printf( " top_element = %d top = %d " ,array[top_element],top_element);
}
int top( void )
{
assert( ! is_empty());
return array[top_element] ;
}
void pop( void )
{
assert( ! is_empty());
array[top_element] = 0 ;
top_element -= 1 ;
}
//
// 17_2_2.cpp
// static array achieve stack
// by:chlaws
//
#include < stdio.h >
#include < stdlib.h >
#include < string .h >
#include " stack.c "
#define stack_size 100
int array[stack_size] = { 3 , 2 , 1 , 4 , 2 , 3 , 6 };
int top_element = - 1 ;
/* int push(int value);
int top(void);
void pop(void);
void is_empty(void);
void is_full(void);
*/
int main( void )
{
int len = - 1 ;
while (array[ ++ len] != 0 );
top_element += len;
int clue_on = 0 ;
do {
int num;
int bois_key;
char notic[] = {
" 1.>push num. "
" 2.>get top_element. "
" 3.>pop num. "
" 4.>look over stact is empty. "
" 5.>look over stact is full. "
};
puts(notic);
fflush(stdin);
scanf( " %d " , & bois_key);
printf( " bois_key = %d " ,bois_key);
fflush(stdin);
switch (bois_key)
{
case 1 : scanf( " %d " , & num);push(num); break ;
case 2 : printf( " top_element = %d " ,top()); break ;
case 3 : pop(); break ;
case 4 : if (is_empty())printf( " stack is empty! " );
else printf( " no empty " );
break ;
case 5 : if (is_full())printf( " stack is full " );
else printf( " no full! " );
break ;
default : exit( 1 );
}
printf( " input:1>contine 2>end " );
fflush(stdin);
scanf( " %d " , & clue_on);
} while (clue_on == 1 ); // regard if you continue to clue_on
return 0 ;
}
// 17_2_2.cpp
// static array achieve stack
// by:chlaws
//
#include < stdio.h >
#include < stdlib.h >
#include < string .h >
#include " stack.c "
#define stack_size 100
int array[stack_size] = { 3 , 2 , 1 , 4 , 2 , 3 , 6 };
int top_element = - 1 ;
/* int push(int value);
int top(void);
void pop(void);
void is_empty(void);
void is_full(void);
*/
int main( void )
{
int len = - 1 ;
while (array[ ++ len] != 0 );
top_element += len;
int clue_on = 0 ;
do {
int num;
int bois_key;
char notic[] = {
" 1.>push num. "
" 2.>get top_element. "
" 3.>pop num. "
" 4.>look over stact is empty. "
" 5.>look over stact is full. "
};
puts(notic);
fflush(stdin);
scanf( " %d " , & bois_key);
printf( " bois_key = %d " ,bois_key);
fflush(stdin);
switch (bois_key)
{
case 1 : scanf( " %d " , & num);push(num); break ;
case 2 : printf( " top_element = %d " ,top()); break ;
case 3 : pop(); break ;
case 4 : if (is_empty())printf( " stack is empty! " );
else printf( " no empty " );
break ;
case 5 : if (is_full())printf( " stack is full " );
else printf( " no full! " );
break ;
default : exit( 1 );
}
printf( " input:1>contine 2>end " );
fflush(stdin);
scanf( " %d " , & clue_on);
} while (clue_on == 1 ); // regard if you continue to clue_on
return 0 ;
}