Skip to content

Instantly share code, notes, and snippets.

@d3v-null
Created May 16, 2017 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d3v-null/9d0a7af1f6d4bd3f4c8167c5cc37d7fc to your computer and use it in GitHub Desktop.
Save d3v-null/9d0a7af1f6d4bd3f4c8167c5cc37d7fc to your computer and use it in GitHub Desktop.
class ETNode {
public:
char value;
ETNode *left, *right;
ETNode(char value_);
ETNode(char value_, ETNode* left_, ETNode* right_);
};
// A very simple expression tree class that converts a parenthesized input
// consisting of addition and multiplication operations, into an expression tree.
// Traversal of this expression tree generates various Polish notations.
class Expression_Tree {
public:
Expression_Tree() { root = 0; };
~Expression_Tree() { clear(root); }
void build_expression_tree(char[], int);
void inorder() { inorder(root); }
void preorder() { preorder(root); }
void postorder() {postorder(root); }
private:
ETNode* root;
void visit(ETNode*);
void inorder(ETNode*);
void preorder(ETNode*);
void postorder(ETNode*);
void clear(ETNode*);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment