Пример #1
0
void stackTest()
{
    cout << "Stack test:" << endl;
    AbstractStack<int>* stack = new StackByArray<int>;
    stackIsEmpty(stack);

    const int iter = 12;
    for (int i = 0; i < iter; ++i)
    {
        cout << "Enter value ";
        int val;
        cin >> val;
        cout << " push " << val << endl;
        stack->push(val);
    }
    stackIsEmpty(stack);
    for (int i = 0; i < iter; ++i)
    {
        cout << "Top element: " << stack->top() << endl;
        cout << "Pop element: " << stack->pop() << endl;
    }
    stackIsEmpty(stack);
    delete stack;
}
Пример #2
0
void printStack(AbstractStack<int>& stack) {
	while (!stack.empty())
		cout << stack.pop() << endl;
}