Skip to content

Instantly share code, notes, and snippets.

@tooshitaka
Created March 18, 2017 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tooshitaka/0cfcd8f0a171076b72aae9bc0e06ecad to your computer and use it in GitHub Desktop.
Save tooshitaka/0cfcd8f0a171076b72aae9bc0e06ecad to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
const int max_size = 101;
int que[max_size];
int top = 0;
bool isFull()
{
return top == max_size;
}
bool isEmpty()
{
return top == 0;
}
void push(int key)
{
if (isFull())
cout << "Stack is Full" << endl;
que[top++] = key;
}
int pop()
{
if (isEmpty())
cout << "Stack is EMPTY" << endl;
return (que[--top]);
}
int main(int argc, char** argv)
{
string s;
while (cin >> s) {
if (s == "+") {
int a, b;
a = pop();
b = pop();
push(a + b);
}
else if (s == "-") {
int a, b;
a = pop();
b = pop();
push(b - a);
}
else if (s == "*") {
int a, b;
a = pop();
b = pop();
push(b * a);
}
else
push(atoi(s.c_str()));
}
cout << pop() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment