Created
April 8, 2021 15:30
-
-
Save laxmankumar2000/d3e5c9eca9f33cd354aa2ef310874fa0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class node { | |
int data; | |
node left; | |
node right; | |
public node(int data) { | |
this.data = data; | |
left = right = null; | |
} | |
} | |
public class debug{ | |
node root; | |
public void insert() | |
{ | |
// node root = new node(60); | |
node n1 = new node(50); | |
node n2 = new node(40); | |
node n3 = new node(30); | |
node n4 = new node(20); | |
root = n1; | |
root.left = n2; | |
root.right = n3; | |
root.left.left=n4 ; //or we can write n1.left = n3; | |
// root.right.right = n4; // or we can write n2.right = n4; | |
} | |
public void preOrderTraversal(node root){ | |
if(root==null) { | |
return; | |
} | |
System.out.println(root.data); | |
preOrderTraversal(root.left); | |
preOrderTraversal(root.right); | |
} | |
} | |
class Garima | |
{ | |
public static void main(String[] args) { | |
debug obj1 = new debug(); | |
obj1.insert(); | |
obj1.preOrderTraversal(obj1.root); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment