Created
March 18, 2017 07:12
-
-
Save tooshitaka/0cfcd8f0a171076b72aae9bc0e06ecad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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