Stack.cpp 674 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Stack.cpp
  3. *
  4. * Created on: 15 Apr 2013
  5. * Author: s0965328
  6. */
  7. #include <cstddef>
  8. #include <math.h>
  9. #include <cassert>
  10. #include "Stack.h"
  11. namespace AutoDiff {
  12. Stack* Stack::vals = NULL;
  13. Stack* Stack::diff = NULL;
  14. Stack::Stack()
  15. {
  16. }
  17. Stack::~Stack() {
  18. this->clear();
  19. }
  20. double Stack::pop_back()
  21. {
  22. assert(this->lifo.size()!=0);
  23. double v = this->lifo.top();
  24. lifo.pop();
  25. return v;
  26. }
  27. void Stack::push_back(double& v)
  28. {
  29. assert(!isnan(v));
  30. this->lifo.push(v);
  31. }
  32. double& Stack::peek()
  33. {
  34. return this->lifo.top();
  35. }
  36. unsigned int Stack::size()
  37. {
  38. return this->lifo.size();
  39. }
  40. void Stack::clear()
  41. {
  42. while(!this->lifo.empty())
  43. {
  44. this->lifo.pop();
  45. }
  46. }
  47. }