Skip to content

Commit f2ebced

Browse files
committed
Added binary_tree.cpp
1 parent e483259 commit f2ebced

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

classical_algorithms/Linear Search .py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def linear(arr,n,x):
1111
if (result == -1):
1212
print("Element not found")
1313
else:
14-
print("Element found at" ,result+1,"position")
14+
print("Element found at" ,result+1,"pos")
1515

1616

1717

classical_algorithms/binary_tree.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
struct Node {
5+
int data;
6+
struct Node* left;
7+
struct Node* right;
8+
9+
// val is the key or the value that
10+
// has to be added to the data part
11+
Node(int val)
12+
{
13+
data = val;
14+
15+
// Left and right child for node
16+
// will be initialized to null
17+
left = NULL;
18+
right = NULL;
19+
}
20+
};
21+
22+
int main()
23+
{
24+
25+
/*create root*/
26+
struct Node* root = new Node(1);
27+
/* following is the tree after above statement
28+
29+
1
30+
/ \
31+
NULL NULL
32+
*/
33+
34+
root->left = new Node(2);
35+
root->right = new Node(3);
36+
/* 2 and 3 become left and right children of 1
37+
1
38+
/ \
39+
2 3
40+
/ \ / \
41+
NULL NULL NULL NULL
42+
*/
43+
44+
root->left->left = new Node(4);
45+
/* 4 becomes left child of 2
46+
1
47+
/ \
48+
2 3
49+
/ \ / \
50+
4 NULL NULL NULL
51+
/ \
52+
NULL NULL
53+
*/
54+
55+
return 0;
56+
}

classical_algorithms/binary_tree.exe

46.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)