command input in function?
Hi,
not sure about the thread name, but tried to describe my problem good. Tried searching too, but didn't really find anything useful :(
Got a binarysearchtree task at school. Got the tree set ut and now I am writing functions for calculating height, depths etc. Got at traversal function that calls it self recursive, and it works like a charm :):
Code:
public void traversal(BinNode<E> n) {
if (n != null) {
// DO PREFIX
traverser(n.left);
// DO INFIX
traverser(n.right);
// DO POSTFIX
}
}
Is it possible to add an argument that i want to run in this function? Like this:
Code:
public void traversal(BinNode<E> n, command toexecute) {
...
//DO INFIX
execute(toexecute)
...
}
So if I call it:
traversal(root, System.out.println(n.data));
It will print out n.data infix (or whereever i placed execute(toexecute))?
I solved my school task, but there i made alot of traversal functions, and it would be so much neater if it is possible to do it this way? :)