-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinorder_successor.cpp
More file actions
51 lines (42 loc) · 1.12 KB
/
inorder_successor.cpp
File metadata and controls
51 lines (42 loc) · 1.12 KB
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
43
44
45
46
47
48
49
50
51
//
// Created by Mayank Parasar on 2020-07-18.
//
/*
* Given a node in a binary search tree (may not be the root),
* find the next largest node in the binary search tree (also known as an inorder successor).
* The nodes in this binary search tree will also have a parent field to traverse up the tree.
Here's an example and some starter code:
class Node:
def __init__(self, value, left=None, right=None, parent=None):
self.value = value
self.left = left
self.right = right
self.parent = parent
def __repr__(self):
return f"(Value: {self.value}, Left: {self.left}, Right: {self.right})"
def inorder_successor(node):
# Fill this in.
tree = Node(3)
tree.left = Node(2)
tree.right = Node(4)
tree.left.parent = tree
tree.right.parent = tree
tree.left.left = Node(1)
tree.left.left.parent = tree.left
tree.right.right = Node(5)
tree.right.right.parent = tree.right
# 3
# / \
# 2 4
# / \
# 1 5
print(inorder_successor(tree.left))
# 3
print(inorder_successor(tree.right))
# 5*/
#include <iostream>
using namespace std;
int main() {
cout << "Testing the project " << endl;
return 0;
}