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

Appearance settings
Merged

Sp7 #172

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions 58 Miscellaneous/Binary_Search_Tree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
public class Binary_Search_Tree {

private static class Node {
int data;
Node left;
Node right;

public Node(int data) {
this.data = data;
}
}

public static Node insert(Node root, int val) {

if (root == null) {
root = new Node(val);
return root;
}

if (root.data > val) {
root.left = insert(root.left, val);
} else {
root.right = insert(root.right, val);
}

return root;
}

public static void inorder(Node root) {

if(root == null)
return;

inorder(root.left);

System.out.println(root.data + " ");

inorder(root.right);
}

public static void main(String[] args) {
// TODO Auto-generated method stub

int value[] = {3, 4, 6, 2, 7, 9, 5, 8};

Node root = null;

for(int i = 0; i < value.length; i++) {
root = insert(root, value[i]);
}

inorder(root);
}

}


// Source: https://www.youtube.com/shorts/PVazOskZlfY
Morty Proxy This is a proxified and sanitized view of the page, visit original site.