!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! This file is an example of how to use the Stack class, by Fredrik Ramsberg. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Include ">stack.h"; ! Set up stack 1 Array stack1tab table 3; ! Last argument states max # of items on stack Stack stack1 "Stack 1" with stacktable stack1tab; ! Set up stack 2 Array stack2tab table 10; ! Last argument states max # of items on stack Stack stack2 "Stack 2" with stacktable stack2tab, failure 10001, success 10002; ! Set up some test data Array ToBePushed --> 3 19 37; ! Main program [main i x problem; ! Push values onto stack 1 while(i++<3) { x=ToBePushed-->(i-1); if(stack1.push(x)~=stack1.failure) print "Pushed ", x, " onto stack 1^"; else { print "Failure!^"; i=10000; } } print "^"; ! Push values onto stack 2 i=0; while(i++<4) { x=random(7)-4; if(stack2.push(x)~=stack2.failure) print "Pushed ", x, " onto stack 2^"; else { print "Failure!^"; i=10000; } } print "^"; print "Size of stack 1: ",stack1.size(), "^"; print "Size of stack 2: ",stack2.size(), "^"; print "# of elements on stack 1: ",stack1.element_count(), "^"; print "# of elements on stack 2: ",stack2.element_count(), "^"; print "^"; ! Pop all values off stack 1 problem=false; while(~~problem) { x=stack1.pop(); if(stack1.status==stack1.success) print "Popped ", x, " from stack 1^"; else problem=true; } print "^"; ! Pop all values off stack 2 problem=false; while(~~problem) { x=stack2.pop(); if(stack2.status==stack2.success) print "Popped ", x, " from stack 2^"; else problem=true; } ];