Posted By

ppofuk on 11/15/10


Tagged

array stack polje stog


Versions (?)

Implementacija stoga pomocu polja


 / Published in: C++
 

  1. #ifndef ATP_STOG
  2. #define ATP_STOG
  3.  
  4. #ifdef STACK_TYPE
  5.  
  6. #define _S_NAME stog
  7. #define _S_INIT InitS
  8. #define _S_P_NAME S
  9. #define _S_EMPTY_NAME IsEmpty
  10. #define _S_TOP_NAME TopS
  11. #define _S_TOP PushS
  12. #define _S_ADD_E x
  13. #define _S_POP PopS
  14. #define STACK_TYPE_ARRAY
  15. #define MAXLENGTH 1000
  16.  
  17. typedef STACK_TYPE element_t;
  18. typedef struct _stack
  19. {
  20. element_t elements[MAXLENGTH];
  21. unsigned short cursor;
  22. } _S_NAME;
  23.  
  24. #define _NEW_STACK(name) \
  25. _S_NAME *name = new _stack;
  26.  
  27. static inline void _S_INIT (_S_NAME* _S_P_NAME)
  28. {
  29. _S_P_NAME->cursor = MAXLENGTH - 1;
  30. }
  31.  
  32. static inline bool _S_EMPTY_NAME (_S_NAME* _S_P_NAME)
  33. {
  34. return _S_P_NAME->cursor >= MAXLENGTH - 1;
  35. }
  36.  
  37. static inline element_t _S_TOP_NAME (_S_NAME* _S_P_NAME)
  38. {
  39. return _S_P_NAME->elements[_S_P_NAME->cursor];
  40. }
  41.  
  42. static inline void _S_TOP (element_t _S_ADD_E, _S_NAME* _S_P_NAME)
  43. {
  44. if (! _S_P_NAME->cursor) return;
  45. _S_P_NAME->elements[--(_S_P_NAME->cursor)] = _S_ADD_E;
  46. }
  47.  
  48. static inline void _S_POP (_S_NAME* _S_P_NAME)
  49. {
  50. if (_S_EMPTY_NAME(_S_P_NAME)) return;
  51. _S_P_NAME->cursor++;
  52. }
  53.  
  54. #endif
  55. #endif

Report this snippet  

You need to login to post a comment.