Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7384a22

Browse files
committed
Code Edits
1 parent 90070c0 commit 7384a22

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed
Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
package trees;
22

3+
import java.util.ArrayDeque;
4+
import java.util.Queue;
5+
6+
import trees.InorderTraversal.Node;
7+
38
public 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

525
public 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
}

‎src/trees/IdenticalBinaryTrees.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package trees;
22
//Given roots of two binary trees, determine if these trees are identical or not.
33

4-
5-
64
public class IdenticalBinaryTrees {
75

86
Node root;

‎src/trees/InorderTraversal.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.util.Stack;
44

5-
import trees.IdenticalBinaryTrees.Node;
6-
75
public class InorderTraversal {
86

97
static class Node{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /