Skip to content

Instantly share code, notes, and snippets.

@laxmankumar2000
Created April 8, 2021 15:21
Show Gist options
  • Save laxmankumar2000/29ad1f156419067d2a4e599a52bc17e8 to your computer and use it in GitHub Desktop.
Save laxmankumar2000/29ad1f156419067d2a4e599a52bc17e8 to your computer and use it in GitHub Desktop.
Linked_list trree
package Tree;
import Tree.BinaryTree.Node;
public class Newclass {
Tree.BinaryTree.Node root;
public void Create_Tree()
{
Tree.BinaryTree.Node n1 = new Tree.BinaryTree.Node(60);
Tree.BinaryTree.Node n2 = new Tree.BinaryTree.Node(50);
Tree.BinaryTree.Node n3 = new Tree.BinaryTree.Node(40);
Tree.BinaryTree.Node n4 = new Tree.BinaryTree.Node(30);
Tree.BinaryTree.Node n5 = new Tree.BinaryTree.Node(10);
Tree.BinaryTree.Node n6 = new Tree.BinaryTree.Node(80);
Tree.BinaryTree.Node n7 = new Node(90);
root = n1;
root.left = n2;
root.right = n3;
n2.left = n4;
n2.right = n5;
n3.left = n6;
n4.right = n7;
}
public void InOrderTraversal(Node root) {
if (root == null) {
return;
}
InOrderTraversal(root.left);
System.out.println(root.data);
InOrderTraversal(root.right);
}
}
class Garima1{
public static void main(String[] args) {
Newclass obj = new Newclass();
obj.Create_Tree();
obj.InOrderTraversal(obj.root);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment