MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / insert

Method insert

Java/SearchingAlgorithms/BFS/BST.java:21–50  ·  view source on GitHub ↗
(int value)

Source from the content-addressed store, hash-verified

19
20 // insert
21 public void insert(int value){
22 if(root == null){
23 Node n = new Node(value);
24 root = n;
25 }
26 else{
27 Node tmp = root;
28 while(true){
29 if(value >= tmp.value){
30 if(tmp.right == null){
31 tmp.right = new Node(value);
32 break;
33 }
34 else{
35 tmp = tmp.right;
36 }
37 }
38 else{
39 if(tmp.left == null){
40 tmp.left = new Node(value);
41 break;
42 }
43 else{
44 tmp = tmp.left;
45 }
46 }
47 }
48 tmp = null;
49 }
50 }
51
52 // find/lookup
53 public boolean contains(int value){

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected