Skip to content

Commit 7268ac5

Browse files
committed
fix arrow pointer error
1 parent 80ee47d commit 7268ac5

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

BST/bst.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,53 @@ struct node {
1010
};
1111
struct node * insert(int n) {
1212
struct node * temp = new struct node();
13-
temp - > val = n;
14-
temp - > left = NULL;
15-
temp - > right = NULL;
13+
temp -> val = n;
14+
temp -> left = NULL;
15+
temp -> right = NULL;
1616
return temp;
1717
}
1818
void inorder(struct node * root) {
1919
if (root != NULL) {
20-
inorder(root - > left);
21-
cout << root - > val << " ";
22-
arr.push_back(root - > val);
23-
inorder(root - > right);
20+
inorder(root -> left);
21+
cout << root -> val << " ";
22+
arr.push_back(root -> val);
23+
inorder(root -> right);
2424
}
2525
}
2626
void postorder(struct node * root) {
2727
if (root != NULL) {
28-
postorder(root - > right);
29-
postorder(root - > left);
30-
cout << root - > val << " ";
28+
postorder(root -> right);
29+
postorder(root -> left);
30+
cout << root -> val << " ";
3131
}
3232
}
3333
void preorder(struct node * root) {
3434
if (root != NULL) {
35-
cout << root - > val << " ";
36-
preorder(root - > left);
37-
preorder(root - > right);
35+
cout << root -> val << " ";
36+
preorder(root -> left);
37+
preorder(root -> right);
3838
}
3939
}
4040
struct node * create(struct node * root, int n) {
4141
if (root == NULL)
4242
insert(n);
43-
else if (root - > val > n) {
44-
root - > left = create(root - > left, n);
43+
else if (root -> val > n) {
44+
root -> left = create(root -> left, n);
4545
} else
46-
root - > right = create(root - > right, n);
46+
root -> right = create(root -> right, n);
4747
}
4848

4949
bool find(struct node * root, int key) {
50-
if (root - > val > key && root - > left == NULL)
50+
if (root -> val > key && root -> left == NULL)
5151
return 0;
52-
if (root - > val < key && root - > right == NULL)
52+
if (root -> val < key && root -> right == NULL)
5353
return 0;
54-
if (root - > val == key)
54+
if (root -> val == key)
5555
return 1;
56-
else if (root - > val > key) {
57-
find(root - > left, key);
58-
} else if (root - > val < key) {
59-
find(root - > right, key);
56+
else if (root -> val > key) {
57+
find(root -> left, key);
58+
} else if (root -> val < key) {
59+
find(root -> right, key);
6060
} else
6161
return 0;
6262
}

0 commit comments

Comments
 (0)