Ejemplo n.º 1
0
int main() {

	Op* op3 = new Op(3);
	Op* op4 = new Op(4);
	Op* op2 = new Op(2);
	Add* add = new Add(op3, op4);
	Sqr* sqr = new Sqr(op2);
	Sub* sub = new Sub(add, sqr);
	Root* root = new Root(sub);

    PrintVisitor *a = new PrintVisitor();


	cout << "--- PreOrder Iteration ---" << endl;
	PreOrderIterator* pre_itr = new PreOrderIterator(root);
	for(pre_itr->first(); !pre_itr->is_done(); pre_itr->next()) {
		pre_itr->current()->accept(a);
	}
    a->execute();
 };
Ejemplo n.º 2
0
int main() {

	Op* op3 = new Op(3);
	Op* op4 = new Op(4);
	Op* op2 = new Op(2);
	Add* add = new Add(op3, op4);
	Sqr* sqr = new Sqr(op2);
	Sub* sub = new Sub(add, sqr);
	Root* root = new Root(sub);
	
    
    cout << "--- PreOrder Iteration ---" << endl;
    PrintVisitor* pVis = new PrintVisitor;

	PreOrderIterator* pre_itr = new PreOrderIterator(root);
	for(pre_itr->first(); !pre_itr->is_done(); pre_itr->next()) {
		pre_itr->current()->accept(pVis);
	}

    pVis->execute();

    Op* op5 = new Op(5);
    Op* op11 = new Op(11);
    Add* add2 = new Add(op5, op11);
    Sub* sub2 = new Sub(add2, sub);
    Sqr* sqr2 = new Sqr(sub2);
    Root* root2 = new Root(sqr2);

    cout << "--- PreOrder Iteration 2---" << endl;
    PrintVisitor* pVis2 = new PrintVisitor;

    PreOrderIterator* pre_itr2 = new PreOrderIterator(root2);
    for(pre_itr2->first(); !pre_itr2->is_done(); pre_itr2->next()) {
        //pre_itr2->current()->print();
        //cout << endl;
        pre_itr2->current()->accept(pVis2);
    }

    pVis2->execute();
                                

    Root* root3 = new Root(0);

    cout << "--- PreOrder Iteration 3---" << endl;
    PrintVisitor* pVis3 = new PrintVisitor;

    PreOrderIterator* pre_itr3 = new PreOrderIterator(root3);
    for(pre_itr3->first(); !pre_itr3->is_done(); pre_itr3->next()) {
        //pre_itr3->current()->print();
        //cout << endl;
        pre_itr3->current()->accept(pVis3);
    }

    pVis3->execute();


    Root* root4 = new Root(op4);

    cout << "--- PreOrder Iteration 2---" << endl;
    PrintVisitor* pVis4 = new PrintVisitor;

    PreOrderIterator* pre_itr4 = new PreOrderIterator(root4);
    for(pre_itr4->first(); !pre_itr4->is_done(); pre_itr4->next()) {
        //pre_itr4->current()->print();
        //cout << endl;
        pre_itr4->current()->accept(pVis4);
    }
     
    pVis4->execute();

};