#pragma once
#include "Complex.h"
#include <iostream>
using std::istream;
using std::ostream;

class Expression
{
    struct Node
    {
        char op;
        Complex operand;
        Node *left, *right;
        Node(char op1, Complex operand1, Node* left1, Node* right1)
            :op(op1), operand(operand1), left(left1), right(right1) {}
    };
    class TreeNodeStack
    {
    public:
        TreeNodeStack();
        virtual ~TreeNodeStack();
        void push(Node *data);
        int pop(Node *&data);
    private:
        Node *m_data[100];
        int m_top;    
    };
public:
    Expression(istream &is);
    virtual ~Expression();
    void inorderPrint(ostream &os);
    Complex evaluate();
    Expression(const Expression &src);
private:
    Node *cloneTree(Node *ptr);
    Expression &operator=(const Expression &rhs);
    Complex evaluate(Node *ptr);
    void inorderPrint(ostream &os, Node *ptr);
    void perform(char op, Complex &operand1, const Complex &operand2);
    void freeTree(Node *ptr);

    Node *m_root;
};

