//-------------------------------------------------------------------------- // author: George (Jiri) Matas g.matas@ee.surrey.ac.uk //-------------------------------------------------------------------------- //static const //char rcsid[] = "$Id: exStack.cc,v 2.11 1998/07/31 16:01:55 ees1cg Exp $"; #include #include #include #include "amma/Stack.hh" #include "amma/StackIt.hh" #include // for exception handling int main() { #ifdef EXCEPTIONS_OK try { #endif StackG s; StackIterG it(s); // can I safely iterate through an empty stack? for(;it.IsElm();it.Next()); FOR_STACKG(it) ; for(int i = 0; i <50 ; i++) { s.Push(i+5); s.DbPrint(); } cout << "Size: " << s.Size() << '\n'; cout << "Pop: " << s.Pop() << '\n'; cout << "Top: " << s.Top() << '\n'; cout << "First:" << s.First() << '\n'; //---------------- Check iterators ----------------------------- FOR_STACKG(it) cout << it.Data() << ' '; cout<< '\n'; StackG s2(s); //----------------------- while(!s.IsEmpty()) { s.Pop(); s.DbPrint(); } cout << "Size: " << s.Size() << '\n'; //----------------------- StackIterG it2(s2); cout << "Iterate: " << '\n'; FOR_STACKG(it2) cout << it2.Data() << " " ; cout << '\n'; cout << "Size s2: " << s2.Size() << '\n'; s.Pop(); // Should cause an error #ifdef EXCEPTIONS_OK } catch(StringC err_mess) { cerr << err_mess << '\n'; return 1; } #endif return 0; }