home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch8 / stack.h < prev    next >
Text File  |  2005-06-16  |  2KB  |  51 lines

  1. /*                           stack.h
  2.  *
  3.  *  Contains the declaration of the data type STACK and the
  4.  *  declarations of the stack utility functions. This header
  5.  *  file should be included in every C source file that 
  6.  *  references a STACK or any of its utility functions.
  7.  */
  8.  
  9. /* Constant Definitions */
  10. #define MAX 8                                   /* Note 1 */
  11.  
  12. /* Type Descriptions */
  13. typedef  struct {
  14.      char  elts[MAX];
  15.      int   top;
  16. } STACK;                                        /* Note 2 */
  17.  
  18. /* Stack Utility Function Prototypes */
  19. int push( char item, STACK *s_ptr );            /* Note 3 */
  20. /* PRECONDITION:  s_ptr contains the address of a STACK.
  21.  *
  22.  * POSTCONDITION: Puts a new item on the stack and adjusts top. 
  23.  */
  24.  
  25. int pop( STACK *s_ptr );
  26. /* PRECONDITION:  s_ptr contains the address of a STACK.
  27.  *
  28.  * POSTCONDITION: Removes an item from the top of the stack, adjusts 
  29.  *                top, and returns the removed item, or -1 if the 
  30.  *                stack was empty. 
  31.  */
  32.  
  33. void init_stack( STACK *s_ptr );
  34. /* PRECONDITION:  s_ptr contains the address of a STACK.
  35.  *
  36.  * POSTCONDITION: Initializes a stack to an empty state by setting 
  37.  *                top beyond the end of the array. 
  38.  */
  39.  
  40. int  is_empty( STACK s );
  41. /* PRECONDITION:  s is a STACK structure.
  42.  *
  43.  * POSTCONDITION: Returns 1 if the STACK is empty and 0 if not. 
  44.  */
  45.  
  46. int  is_full( STACK s );
  47. /* PRECONDITION:  s is a STACK structure.
  48.  *
  49.  * POSTCONDITION: Returns 1 if the STACK is full, and 0 if not. 
  50.  */
  51.