Skip to content

Commit b790587

Browse files
Update
1 parent e4517c6 commit b790587

File tree

3 files changed

+142
-32
lines changed

3 files changed

+142
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/.metadata/
2+
*.pyc

.vscode/launch.json

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Current File",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${file}"
12+
},
13+
{
14+
"name": "Python: Attach",
15+
"type": "python",
16+
"request": "attach",
17+
"localRoot": "${workspaceFolder}",
18+
"remoteRoot": "${workspaceFolder}",
19+
"port": 3000,
20+
"secret": "my_secret",
21+
"host": "localhost"
22+
},
23+
{
24+
"name": "Python: Terminal (integrated)",
25+
"type": "python",
26+
"request": "launch",
27+
"program": "${file}",
28+
"console": "integratedTerminal"
29+
},
30+
{
31+
"name": "Python: Terminal (external)",
32+
"type": "python",
33+
"request": "launch",
34+
"program": "${file}",
35+
"console": "externalTerminal"
36+
},
37+
{
38+
"name": "Python: Django",
39+
"type": "python",
40+
"request": "launch",
41+
"program": "${workspaceFolder}/manage.py",
42+
"args": [
43+
"runserver",
44+
"--noreload",
45+
"--nothreading"
46+
],
47+
"debugOptions": [
48+
"RedirectOutput",
49+
"Django"
50+
]
51+
},
52+
{
53+
"name": "Python: Flask (0.11.x or later)",
54+
"type": "python",
55+
"request": "launch",
56+
"module": "flask",
57+
"env": {
58+
"FLASK_APP": "${workspaceFolder}/app.py"
59+
},
60+
"args": [
61+
"run",
62+
"--no-debugger",
63+
"--no-reload"
64+
]
65+
},
66+
{
67+
"name": "Python: Module",
68+
"type": "python",
69+
"request": "launch",
70+
"module": "module.name"
71+
},
72+
{
73+
"name": "Python: Pyramid",
74+
"type": "python",
75+
"request": "launch",
76+
"args": [
77+
"${workspaceFolder}/development.ini"
78+
],
79+
"debugOptions": [
80+
"RedirectOutput",
81+
"Pyramid"
82+
]
83+
},
84+
{
85+
"name": "Python: Watson",
86+
"type": "python",
87+
"request": "launch",
88+
"program": "${workspaceFolder}/console.py",
89+
"args": [
90+
"dev",
91+
"runserver",
92+
"--noreload=True"
93+
]
94+
},
95+
{
96+
"name": "Python: All debug Options",
97+
"type": "python",
98+
"request": "launch",
99+
"pythonPath": "${config:python.pythonPath}",
100+
"program": "${file}",
101+
"module": "module.name",
102+
"env": {
103+
"VAR1": "1",
104+
"VAR2": "2"
105+
},
106+
"envFile": "${workspaceFolder}/.env",
107+
"args": [
108+
"arg1",
109+
"arg2"
110+
],
111+
"debugOptions": [
112+
"RedirectOutput"
113+
]
114+
}
115+
]
116+
}

BinaryTree/Tree.py

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env python
22
from collections import deque
33

4+
45
class Tree(object):
56
class Node(object):
67
def __init__(self, v, l=None, r=None):
78
self.value = v
89
self.lChild = l
9-
self.rChild = r
10-
10+
self.rChild = r
11+
1112
def __init__(self):
1213
self.root = None
1314

@@ -24,7 +25,7 @@ def levelOrderBinaryTreeUtil(self, arr, start):
2425
if right < size:
2526
curr.rChild = self.levelOrderBinaryTreeUtil(arr, right)
2627
return curr
27-
28+
2829
def InsertNode(self, value):
2930
self.root = self.InsertNodeUtil(self.root, value)
3031

@@ -38,75 +39,66 @@ def InsertNodeUtil(self, node, value):
3839
node.rChild = self.InsertNodeUtil(node.rChild, value)
3940
return node
4041

41-
4242
def PrintPreOrder(self):
4343
self.PrintPreOrderUtil(self.root)
4444

45-
4645
def PrintPreOrderUtil(self, node):
47-
# pre order
46+
# pre order
4847
if node != None:
4948
print (node.value),
5049
self.PrintPreOrderUtil(node.lChild)
5150
self.PrintPreOrderUtil(node.rChild)
5251

53-
5452
def NthPreOrder(self, index):
55-
count = [0]
53+
count = [0]
5654
self.NthPreOrderUtil(self.root, index, count)
5755

5856
def NthPreOrderUtil(self, node, index, count):
59-
# pre order
57+
# pre order
6058
if node != None:
6159
count[0] += 1
6260
if count[0] == index:
6361
print (node.value),
6462
self.NthPreOrderUtil(node.lChild, index, count)
6563
self.NthPreOrderUtil(node.rChild, index, count)
6664

67-
6865
def PrintPostOrder(self):
6966
self.PrintPostOrderUtil(self.root)
7067

7168
def PrintPostOrderUtil(self, node):
72-
# post order
69+
# post order
7370
if node != None:
7471
self.PrintPostOrderUtil(node.lChild)
7572
self.PrintPostOrderUtil(node.rChild)
7673
print (node.value),
7774

78-
7975
def NthPostOrder(self, index):
8076
count = [0]
8177
self.NthPostOrderUtil(self.root, index, count)
8278

8379
def NthPostOrderUtil(self, node, index, count):
84-
# post order
80+
# post order
8581
if node != None:
8682
self.NthPostOrderUtil(node.lChild, index, count)
8783
self.NthPostOrderUtil(node.rChild, index, count)
8884
count[0] += 1
8985
if count[0] == index:
9086
print (node.value),
9187

92-
9388
def PrintInOrder(self):
9489
self.PrintInOrderUtil(self.root)
9590

96-
9791
def PrintInOrderUtil(self, node):
98-
# In order
92+
# In order
9993
if node != None:
10094
self.PrintInOrderUtil(node.lChild)
10195
print (node.value),
10296
self.PrintInOrderUtil(node.rChild)
10397

104-
10598
def NthInOrder(self, index):
10699
count = [0]
107100
self.NthInOrderUtil(self.root, index, count)
108101

109-
110102
def NthInOrderUtil(self, node, index, count):
111103
if node != None:
112104
self.NthInOrderUtil(node.lChild, index, count)
@@ -135,10 +127,11 @@ def PrintDepthFirst(self):
135127
while stk.isEmpty() == False:
136128
temp = stk.pop()
137129
print (temp.value),
138-
if temp.lChild != None:
139-
stk.append(temp.lChild)
140130
if temp.rChild != None:
141131
stk.append(temp.rChild)
132+
if temp.lChild != None:
133+
stk.append(temp.lChild)
134+
142135

143136
def Find(self, value):
144137
curr = self.root
@@ -638,12 +631,12 @@ def treeToListRec(self, curr):
638631
return Head
639632

640633

641-
#=======================================================================
634+
# =======================================================================
642635
# arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
643636
# t2 = Tree()
644637
# t2.levelOrderBinaryTree(arr)
645-
#=======================================================================
646-
#=======================================================================
638+
# =======================================================================
639+
# =======================================================================
647640
# t = Tree()
648641
# arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
649642
# # t.levelOrderBinaryTree(arr)
@@ -674,11 +667,11 @@ def treeToListRec(self, curr):
674667
# t.PrintBredthFirst()
675668
# # t.treeToList();
676669
# print ( t.LCA(10, 3) )
677-
#=======================================================================
670+
# =======================================================================
678671
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
679672
t2 = Tree()
680673
# t2.levelOrderBinaryTree(arr)
681-
#=======================================================================
674+
# =======================================================================
682675
# t2.InsertNode(5)
683676
# t2.InsertNode(3)
684677
# t2.InsertNode(4)
@@ -687,10 +680,10 @@ def treeToListRec(self, curr):
687680
# t2.InsertNode(8)
688681
# t2.InsertNode(7)
689682
# t2.InsertNode(9)
690-
#=======================================================================
691-
#print t2.Ancestor(1, 10)
692-
#print t2.CeilBST(7)
693-
#print t2.FloorBST(12)
683+
# =======================================================================
684+
# print t2.Ancestor(1, 10)
685+
# print t2.CeilBST(7)
686+
# print t2.FloorBST(12)
694687
t2.CreateBinaryTree(arr)
695688
t2.PrintInOrder()
696689
print ""
@@ -703,8 +696,8 @@ def treeToListRec(self, curr):
703696
t2.PrintPreOrder()
704697
print ""
705698
t2.iterativePreOrder()
706-
#t2.DeleteNode(8)
707-
#=======================================================================
699+
# t2.DeleteNode(8)
700+
# =======================================================================
708701
# t3 = t2.CopyMirrorTree()
709702
# t2.PrintInOrder()
710703
# print ""
@@ -737,5 +730,5 @@ def treeToListRec(self, curr):
737730
# print t2.printInRange(4, 7)
738731
# print t2.trimOutsideRange(3, 8)
739732
# print t2.PrintInOrder()
740-
#=======================================================================
733+
# =======================================================================
741734

0 commit comments

Comments
 (0)