-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequentialBST.cpp
More file actions
34 lines (29 loc) · 816 Bytes
/
SequentialBST.cpp
File metadata and controls
34 lines (29 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//Binary Search Tree Program
#include <iostream>
#include <cstdlib>
#include <climits>
#include <vector>
#include <algorithm>
#include "BSTclass.h"
using namespace std;
void SequentialBST::insert(int k)
{
searchResult * s = search(k);
atomic<treeNode*> newInternal;
newInternal.store(s->l);
if(newInternal.load()->data == k){
return;
}
treeNode * newNode = new treeNode(k, true);
treeNode * newSibling = new treeNode(newInternal.load()->data, true);
newInternal.load()->data = max(k, newInternal.load()->data);
newInternal.load()->isLeaf = false;
if(k < newInternal.load()->data){
newInternal.load()->left.store(newNode);
newInternal.load()->right.store(newSibling);
}
else{
newInternal.load()->left.store(newSibling);
newInternal.load()->right.store(newNode);
}
}