File tree Expand file tree Collapse file tree 3 files changed +45
-5
lines changed
Expand file tree Collapse file tree 3 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 11package trees ;
22
3+ import java .util .ArrayDeque ;
4+ import java .util .Queue ;
5+
6+ import trees .InorderTraversal .Node ;
7+
38public class BTreeLevelOrderTraversal {
9+
10+ static class Node {
11+
12+ int data ;
13+ Node left ;
14+ Node right ;
15+
16+ Node (int a ){
17+ this .data = a ;
18+ this .left = null ;
19+ this .right = null ;
20+ }
21+ }
22+
23+ Node root ;
424
525public static void main (String [] args ) {
6- // TODO Auto-generated method stub
26+
27+ BTreeLevelOrderTraversal tree = new BTreeLevelOrderTraversal ();
28+
29+ tree .root = new Node (100 );
30+ tree .root .left = new Node (50 );
31+ tree .root .right = new Node (200 );
32+ tree .root .left .left = new Node (25 );
33+ tree .root .left .right = new Node (75 );
34+ tree .root .right .right = new Node (350 );
35+
36+ level_traverse (tree .root );
37+
38+ }
739
40+ private static void level_traverse (Node root2 ) {
41+
42+ if (root2 ==null ) System .out .println ("Tree is empty" );
43+ Queue <Node > curr = new ArrayDeque <>();
44+
45+ while (!curr .isEmpty ()){
46+ curr .add (root2 );
47+
48+ }
49+
50+
51+
852}
953
1054}
Original file line number Diff line number Diff line change 11package trees ;
22//Given roots of two binary trees, determine if these trees are identical or not.
33
4-
5-
64public class IdenticalBinaryTrees {
75
86Node root ;
Original file line number Diff line number Diff line change 22
33import java .util .Stack ;
44
5- import trees .IdenticalBinaryTrees .Node ;
6-
75public class InorderTraversal {
86
97static class Node {
You can’t perform that action at this time.
0 commit comments