예제 #1
0
void main() {

	ArrayStack myArrayStack;

	myArrayStack.isEmpty();

	myArrayStack.Push(45);
	myArrayStack.Push(4);
	myArrayStack.Push(34);
	myArrayStack.Push(99);
	myArrayStack.Push(1200);
	//myArrayStack.Push(771);		//causes stack overflow

	myArrayStack.isEmpty();
	cout << myArrayStack.Size() << endl;

	cout << "\nTop element: " << myArrayStack.Top() << endl;

	cout << "\nRemoving top element: " << myArrayStack.Pop() << endl;

	cout << "\nCurrent top element: " << myArrayStack.Top() << endl;

	cout << myArrayStack.Size() << endl;


	getchar();

}
예제 #2
0
int main(){
	ArrayStack s;
	try{
		if(s.isEmpty()){
			cout << "Stack is empty"<< endl;
		}
		
		s.Push(349);
		s.Push(49);
		s.Push(679);
		
		// Print size of stack
		cout << "Size of stack = " << s.Size() << endl;
		
		// Print top element in stack
		cout << "Top Element " << s.Top() << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
	}catch(...)
		cout << "Some exception occured." << endl;
	}
	
}