home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / incl / b_stack.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  1.4 KB  |  74 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  b_stack.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17. #ifndef BSTACKH
  18. #define BSTACKH
  19.  
  20. #include <LEDA/basic.h>
  21.  
  22.  
  23. //------------------------------------------------------------------------------
  24. // bounded stacks 
  25. //
  26. // S. Naeher (1989)
  27. //
  28. //------------------------------------------------------------------------------
  29.  
  30. #define b_stack(type) name2(type,b_stack)
  31.  
  32. #define b_stackdeclare(type)\
  33. class b_stack(type) {\
  34.     type* v;\
  35.     int sz;    \
  36.         int t;\
  37. public:\
  38. \
  39. b_stack(type)(int n)\
  40. { if (n<1) error_handler(99,"b_stack: bad size");\
  41.   sz = n;\
  42.   t = -1;\
  43.   v = new type[sz];\
  44.   if (v==0) error_handler(99,"b_stack: out of memory");\
  45.  }\
  46. \
  47. ~b_stack(type)() { delete[0] v; }\
  48. \
  49. int   size()  const { return t+1; }\
  50. int   empty() const { return (t<0) ? true : false; }\
  51. \
  52. void push(type& a)\
  53. { t++;\
  54.   if (t==sz) error_handler(99,"b_stack overflow");\
  55.   v[t] = a;\
  56. }\
  57. \
  58. type pop()\
  59. { if (t<0) error_handler(99,"b_stack underflow");\
  60.   return v[t--];\
  61. }\
  62. \
  63. type top() const \
  64. { if (t<0) error_handler(99,"b_stack empty");\
  65.   return v[t];\
  66. }\
  67. \
  68. void clear() { t = -1; }\
  69. };
  70.  
  71.  
  72. #endif
  73.