- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinTree.cpp
More file actions
Latest commit
43 lines (33 loc) · 693 Bytes
/
Copy pathbinTree.cpp
File metadata and controls
43 lines (33 loc) · 693 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
34
35
36
37
38
39
40
41
42
//
// binTree.cpp
// trees
//
// Created by Abdulaziz Alghamdi on 2017-01-22.
// Copyright © 2017 app. All rights reserved.
//
#include"binTree.h"
binTree::binTree() {
tree = new node[size];
pos = 1;
size = 0;
}
voidbinTree::insert(int newData) {
node temp;
temp.data = newData;
temp.lChild = &tree[pos * 2];
temp.rChild = &tree[(pos * 2) + 1];
tree[pos] = temp;
pos++;
size++;
}
voidbinTree::print() {
cout << "Tree: { ";
for (int i = 1; i < size; i++) {
cout << tree[i].data << ", ";
}
cout << tree[size].data << " }" << '\n';
}
intbinTree::maxDepth() {
int temp = log2(size);
return temp;
}