Posted By

ppofuk on 11/15/10


Tagged

list stack stog


Versions (?)

Implementacija stoga pomocu pokazivaca


 / 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_LIST
  15.  
  16. typedef STACK_TYPE element_t;
  17. typedef struct _stack
  18. {
  19. element_t element;
  20. _stack *next;
  21. } _S_NAME;
  22.  
  23. #define _NEW_STACK(name) \
  24. _S_NAME *name = new _stack
  25.  
  26. static inline void _S_INIT (_S_NAME* _S_P_NAME)
  27. {
  28. _S_P_NAME->next = NULL;
  29. }
  30.  
  31. static inline bool _S_EMPTY_NAME (_S_NAME* _S_P_NAME)
  32. {
  33. return (_S_P_NAME->next == NULL);
  34. }
  35.  
  36. static inline element_t _S_TOP_NAME (_S_NAME* _S_P_NAME)
  37. {
  38. return _S_P_NAME->next->element;
  39. }
  40.  
  41. static inline void _S_TOP (element_t _S_ADD_E ,_S_NAME* _S_P_NAME)
  42. {
  43. _S_NAME *_new_stack = new _stack;
  44. _new_stack->next = _S_P_NAME->next;
  45. _new_stack->element = _S_ADD_E;
  46. _S_P_NAME->next = _new_stack;
  47. }
  48.  
  49. static inline void _S_POP (_S_NAME * _S_P_NAME)
  50. {
  51. _S_NAME *_del_stack = _S_P_NAME->next;
  52. _S_P_NAME->next = _del_stack->next;
  53. delete _del_stack;
  54. }
  55.  
  56. #endif
  57. #endif

Report this snippet  

You need to login to post a comment.