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

Function Insert

Trees/BST.C:11–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9} *root = NULL;
10
11void Insert(int key)
12{
13 struct Node *t = root;
14 struct Node *r, *p;
15
16 if (root == NULL)
17 {
18 p = (struct Node *)malloc(sizeof(struct Node));
19 p->data = key;
20 p->lchild = p->rchild = NULL;
21 root = p;
22 return;
23 }
24 while (t != NULL)
25 {
26 r = t;
27 if (key < t->data)
28 t = t->lchild;
29 else if (key > t->data)
30 t = t->rchild;
31 else
32 return;
33 }
34 p = (struct Node *)malloc(sizeof(struct Node));
35 p->data = key;
36 p->lchild = p->rchild = NULL;
37
38 if (key < r->data)
39 r->lchild = p;
40 else
41 r->rchild = p;
42}
43
44void Inorder(struct Node *p)
45{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected