Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stack<Expression_Tree*> stack;
- for(int i = 0; i < curr_postfix.size(); ++i) {
- if(isdigit(curr_postfix[i])) {
- cout << " kom till isdigit " << endl;
- char c = curr_postfix[i];
- int num = c;
- Expression_Tree* temp = new Integer(c);
- stack.push(temp);
- delete temp;
- }
- if(isalpha(curr_postfix[i])) {
- cout << " kom till isalpha " << endl;
- stringstream ss;
- string s;
- char str = curr_postfix[i];
- ss << str;
- ss >> s;
- Expression_Tree* temp = new Variable(s);
- stack.push(temp);
- delete temp;
- }
- if(curr_postfix[i] == '+') {
- cout << " kom till + " << endl;
- Expression_Tree* left;
- Expression_Tree* right;
- cout << " kom till slut av + " << endl;
- left = stack.top();
- stack.pop();
- right = stack.top();
- stack.pop();
- Expression_Tree* temp = new Plus(left, right);
- stack.push(temp);
- delete temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement