binary trees - Preorder - Inorder

hello guys, i am in a desperate position atm...i "killed" google search engine trying finding a class token and binary tree combine in order to evaluate a preOrder expression to inOrder expression... i really tried everything ... but not enough i guess ... any help is accepted ;) thanks in advance ^^
The variants of recursive depth-first traversal in a binary tree differ only in the order which you look at the children and do work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function pre_order(Node root) { 
  do_work(root); 
  self(root.left_child);
  self(root.right_child); 
}

function in_order(Node root) { 
  self(root.left_child); 
  do_work(root);
  self(root.right_child);
}

function post_order(Node root) { 
  self(root.left_child);
  self(root.right_child);
  do_work(root);
}
Last edited on
yeah i know ... the above code i fegure it out on my own... but what about token and string expressions? how i implemented 2gether?!? I have this task....but as i said i have no idea how to implement.

class input_token {
private:
enum token_type { NUMBER_TOKEN, FUNCTION_TOKEN, VARIABLE_TOKEN, END_TOKEN };
token_type type;
double value; // set when type is NUMBER_TOKEN
string name; // set when type is FUNCTION_TOKEN
public:
// All necessary functions to manipulate the tokens
};

Expression trees are represented using the class expr_tree:
class expr_tree {
private:
expr_tree *left, *right;
input_token token;
public:
expr_tree();
double evaluate(double v);
void print();
expr_tree *read_expr();
};
Last edited on
Topic archived. No new replies allowed.