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