void inOrder(Node root) {
if(root == null){
return ;
}else{
inOrder(root.left);
System.out.print(root.data+" ");
inOrder(root.right);
}
}
void inOrder(Node root) {
if(root == null){
return;
}
Node current = root;
Stack<Node> stack = new Stack<Node>();
stack.push(current);
while(!stack.isEmpty()){
while(current.left != null){
current = current.left;
stack.push(current);
}
while(current.right == null){
if(!stack.isEmpty()){
current = stack.pop();
System.out.print(current.data+" ");
}else{
return;
}
}
current = current.right;
stack.push(current);
}
}
void LevelOrder(Node root)
{
Queue<Node> queue = new LinkedList<Node>();
queue.add(root);
while(!queue.isEmpty()){
Node node = queue.poll();
System.out.print(node.data+" ");
if(node.left != null){
queue.add(node.left);
}
if(node.right != null){
queue.add(node.right);
}
}
}
int longest(Node root){
if(root == null){
return 0;
}else{
return Math.max((longest(root.left)+1),(longest(root.right)+1));
}
}
int height(Node root)
{
return longest(root)-1;
}
void left_view(Node root){
if(root == null){
return ;
}
left_view(root.left);
System.out.print(root.data+" ");
}
void right_view(Node root){
if(root == null){
return;
}
System.out.print(root.data+" ");
right_view(root.right);
}
void top_view(Node root){
left_view(root.left);
System.out.print(root.data+" ");
right_view(root.right);
}
public void createBiTree(){
Scanner scn = null;
try {
scn = new Scanner(new File("input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
this.root = createBiTree(root, scn);
}
private Node<T> createBiTree(Node<T> node, Scanner scn) {
String temp = scn.next();
if(temp.trim().equals("#")){
return null;
}
else{
node = new Node<T>((T)temp);
node.setLeft(createBiTree(node.getLeft(), scn));
node.setRight(createBiTree(node.getRight(), scn));
return node;
}
}