/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#ifndef ATP_STOG #define ATP_STOG #ifdef STACK_TYPE #define _S_NAME stog #define _S_INIT InitS #define _S_P_NAME S #define _S_EMPTY_NAME IsEmpty #define _S_TOP_NAME TopS #define _S_TOP PushS #define _S_ADD_E x #define _S_POP PopS #define STACK_TYPE_ARRAY #define MAXLENGTH 1000 typedef STACK_TYPE element_t; typedef struct _stack { element_t elements[MAXLENGTH]; unsigned short cursor; } _S_NAME; #define _NEW_STACK(name) \ _S_NAME *name = new _stack; static inline void _S_INIT (_S_NAME* _S_P_NAME) { _S_P_NAME->cursor = MAXLENGTH - 1; } static inline bool _S_EMPTY_NAME (_S_NAME* _S_P_NAME) { return _S_P_NAME->cursor >= MAXLENGTH - 1; } static inline element_t _S_TOP_NAME (_S_NAME* _S_P_NAME) { return _S_P_NAME->elements[_S_P_NAME->cursor]; } static inline void _S_TOP (element_t _S_ADD_E, _S_NAME* _S_P_NAME) { if (! _S_P_NAME->cursor) return; _S_P_NAME->elements[--(_S_P_NAME->cursor)] = _S_ADD_E; } static inline void _S_POP (_S_NAME* _S_P_NAME) { if (_S_EMPTY_NAME(_S_P_NAME)) return; _S_P_NAME->cursor++; } #endif #endif