stack.hpp 639 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "semigroup.hpp"
  2. #ifndef STACK_HPP
  3. #define STACK_HPP
  4. #define STACK_SIZE (MAX_GENUS*(MAX_GENUS+1))/2
  5. class Stack{
  6. public:
  7. Semigroup data[STACK_SIZE+1], *stack[STACK_SIZE], *other;
  8. size_t stack_size;
  9. Stack();
  10. Semigroup* pop();
  11. Semigroup* pushed();
  12. bool is_empty();
  13. };
  14. inline
  15. Stack::Stack(){
  16. for (ind_t i=0; i<STACK_SIZE; i++) stack[i] = &(data[i]);
  17. other=&data[STACK_SIZE];
  18. stack_size=0;
  19. }
  20. inline Semigroup*
  21. Stack::pop(){
  22. swap(stack[--stack_size],other);
  23. return other;
  24. }
  25. inline Semigroup*
  26. Stack::pushed(){
  27. return stack[stack_size++];
  28. };
  29. inline bool
  30. Stack::is_empty(){
  31. return stack_size==0;
  32. }
  33. #endif