stack.hpp 595 B

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