#include #include "StackT.h" using namespace std; void FillStack(StackT & dest, size_t size); void EmptyStack(StackT & s); void CheckStack(StackT s, size_t size); void UnderflowTest(StackT & s); int main() { StackT a, b; size_t i; // simple check to see if it will hold different sizes. for(i=1;i<100;i++) { FillStack(a, i); CheckStack(a, i); b = a; CheckStack(b, i); StackT c(a); CheckStack(c, i); EmptyStack(a); } // let's try to underflow the stack now. UnderflowTest(a); return 0; } void UnderflowTest(StackT & s){ size_t i; EmptyStack(s); for(i = 0; i < 10; i++) { int tmp; tmp = s.Top(); if (0 != tmp) { cout << "Top error, should be " << 0 << " but is " << tmp << endl; } tmp = s.Pop(); if (0 != tmp) { cout << "Top error, should be " << 0 << " but is " << tmp << endl; } } return; } void CheckStack(StackT s, size_t size){ int i; int tmp; i = size -1; while ( s.Size()> 0) { tmp = s.Top(); if (i != tmp) { cout << "Top error, should be " << i << " but is " << tmp << endl; } tmp = s.Pop(); if (i != tmp) { cout << "Pop error, should be " << i << " but is " << tmp << endl; } i--; } return; } void FillStack(StackT & dest, size_t size) { size_t i; for(i=0; i 0) { s.Pop(); } return; }