int main() {
    IntStack s;
    s.push(1);
    s.push(2);
    s.pop();
    s.push(3);
    s.pop();
    s.push(4);
    return 0;
}
int main() {
    IntStack s;
    s.push(1);
    s.push(2);
    s.push(3);
    s.clear();
    s.top();
    s.pop();
    return 0;
}
Пример #3
0
int main(int argc, char** argv) {
    ifstream fileInput;
    fileInput.open(argv[1]);
    
    IntStack *stack = new IntStack();
    int value;
    while (fileInput.peek() != EOF) {
        while ((fileInput.peek() != '\n') && (fileInput >> value)) {
            stack->push(value);
        }
        fileInput.get(); // chomp the newline
        while (!stack->isEmpty()) {
            cout << stack->pop() << " ";
            if (!stack->isEmpty()) {
                stack->pop();
            }
        }
        cout << endl;
    }

}
Пример #4
0
int main()
{
	IntStack intStack;
	intStack.push(1);
	intStack.push(2);
	intStack.push(3);
	while (!intStack.empty())
	{
		int t = intStack.top();
		intStack.pop();
		printf("%d\n", t);
	}
	intStack.push(4);
	intStack.push(5);
	while (!intStack.empty())
	{
		int t = intStack.top();
		intStack.pop();
		printf("%d\n", t);
	}
	return 0;
}
Пример #5
0
int main()
{
    IntStack stack;

    int curr;
    char oper;
    char tmp;
    int right, left;

    while(cin >> tmp)
    {
        if(isdigit(tmp))
        {
            cin.putback(tmp);
            cin >> curr;
            stack.push(curr);
        }
        else
        {
            oper = tmp;
            right = stack.pop();
            left = stack.pop();
            switch (oper)
            {
                case '+':
                    stack.push(left + right);
                    break;
                case '-':
                    stack.push(left - right);
                    break;
                case '*':
                    stack.push(left * right);
                    break;
            }
        }
    }
Пример #6
0
int main()
{
    IntStack stack;

    while(true)
    {
        string cmd;
        cin >> cmd;
        if(cmd == "push")
        {
            int elem;
            cin >> elem;
            stack.push(elem);
        }
        if(cmd == "pop")
        {
            stack.pop();
        }
        if(cmd == "top")
        {
            cout << stack.top() << " is at the top" << endl;
        }
        cout << stack << endl;
    }