This is the code
import java.util.*;
public class Main {
public static void main(String args[]) {
BinaryTree tree = new BinaryTree();
tree.leftview();
}
}
class BinaryTree{
Scanner scn = new Scanner(System.in);
private class Node{
int data;
Node left;
Node right;
}
private Node root;
BinaryTree(){
this.root = CreateTree();
}
private Node CreateTree(){
int d = scn.nextInt();
LinkedList q = new LinkedList();
Node nn = new Node();
nn.data = d;
this.root = nn;
q.add(root);
while(!q.isEmpty()){
Node node = q.getFirst();
q.removeFirst();
int c1 = scn.nextInt();
int c2 = scn.nextInt();
if(c1 != -1){
nn = new Node();
nn.data = c1;
node.left = nn;
q.addLast(node.left);
}
if(c2 != -1){
nn = new Node();
nn.data = c2;
node.right = nn;
q.addLast(node.right);
}
}
return root;
}
public void leftview(){
leftview(this.root);
}
private void leftview(Node node){
Node temp = new Node();
temp = node;
while(temp != null){
System.out.print(temp.data + " ");
temp = temp.left;
}
}
}
unsafe or unchecked error
-xlint : unsafe errors