├── README.md └── PreorderGithub.txt /README.md: -------------------------------------------------------------------------------- 1 | # Preorder -------------------------------------------------------------------------------- /PreorderGithub.txt: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Node 3 | { 4 | int key; 5 | Node left,right; 6 | public Node(int data) 7 | { 8 | key=data; 9 | left=right=null; 10 | } 11 | } 12 | class BinaryTree 13 | { 14 | Node root; 15 | 16 | BinaryTree() 17 | { 18 | root=null; 19 | 20 | } 21 | public void insert(int key) 22 | { 23 | root=insertbin(root,key); 24 | } 25 | Node insertbin(Node root,int key) 26 | { 27 | if(root==null) 28 | { 29 | root=new Node(key); 30 | return root; 31 | } 32 | if(keyroot.key) 37 | { 38 | root.right=insertbin(root.right,key); 39 | } 40 | return root; 41 | } 42 | public void intravers(Node node) 43 | { 44 | if (node != null) 45 | { 46 | System.out.print(node.key + "->"); 47 | intravers(node.left); 48 | intravers(node.right); 49 | } 50 | } 51 | 52 | } 53 | 54 | public class Main 55 | { 56 | public static void main(String[] args) 57 | { 58 | Scanner sc=new Scanner(System.in); 59 | BinaryTree tree=new BinaryTree(); 60 | int n=sc.nextInt(); 61 | for(int i=0;i