STACKclass

STACKclass - void stack::push( const int item) { if (count...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
const int STACK_SIZE = 100; class stack { private : int count; // number of items in the stack int data[STACK_SIZE]; public : stack(); ~stack(); void push( const int item); // push an item on the stack int pop( void ); // pop item off the stack }; stack::stack() // constructor { count = 0; // zero the stack } stack::~stack() {} // default destructor
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: void stack::push( const int item) { if (count < STACK_SIZE) { data[count] = item; ++count; } else cout << "Overflow!\n" ; } int stack::pop( void ) { if (count >0) {--count; return (data[count]); } else { cout << "Underflow!\n" ; return 0; } }...
View Full Document

Ask a homework question - tutors are online