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

Function search

CPP/BST/InsertionInABST.cpp:24–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 }
23}
24int search(struct node *root, int key){
25 struct node *prev = NULL;
26 while(root!=NULL){
27 prev = root;
28 if(key==root->data){
29 printf("Cannot insert %d, already in BST", key);
30 return 1;
31 }
32 else if(key<root->data){
33 root = root->left;
34 }
35 else{
36 root = root->right;
37 }
38 }
39 return 0;
40}
41struct node *insert(struct node *node, int key) {
42 if(search(node,key)==0){
43

Callers 4

insertFunction · 0.70
searchMethod · 0.50
goodNodesMethod · 0.50
constructTreeMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected