示例#1
0
int main(int argc, const char * argv[])
{
    ExpTree a;
    a.build();
    cout << "Postorder: ";
    a.print_postorder(a.root);
    cout << endl << "Inorder: ";
    a.print_inorder(a.root);
    cout << endl << "Preorder: ";
    a.print_preorder(a.root);
    cout << endl;
    a.evaluate(a.root);
    return 0;
}
示例#2
0
文件: main.cpp 项目: andeh575/OOInfix
int main(void) {
	string infix;	// Input string
	int solution;	// Solution to the expression tree
	bool control;	// Loop flag to allow multiple iterations of input
	char loop;		// User input for control loop
	ExpTree tree = ExpTree(NULL);	// Declaring an instance of ExpTree
	
	cout << "Welcome to the Improved Infix Equation Solver" << endl;
	control = true;

	// Continue to loop the program until the user presses the 'n' key
	while (control) {
		infix = getInfix();							
		tree.parseExpression(infix, NULL);			// Parse the infix expression and assemble it on the tree
		solution = tree.evaluate(tree.getRoot());	// Evaluate the results of the infix expression

		// Testing for proper arrangement of tree nodes and traversal
		cout << endl << "Pre Order: ";
		tree.preOrder(tree.getRoot());
		
		cout << endl << "In Order: ";
		tree.inOrder(tree.getRoot());

		cout << endl << "Post Order: ";
		tree.postOrder(tree.getRoot());

		cout << endl;

		cout << endl << "The solution to the expression is: " << solution << endl;
		cout << "Do you want to enter another expression (y/n)? ";
		cin >> loop;

		if (loop == 'n')
			control = false;
	}

	system("PAUSE");
	return 0;
}