Skip to content

Commit d9d8405

Browse files
authored
Merge pull request #107 from Gathros/GeneralFixes
Removing useless code in tree traversal.
2 parents 22a0a8a + 7e4bd10 commit d9d8405

File tree

3 files changed

+47
-136
lines changed

3 files changed

+47
-136
lines changed

chapters/tree_traversal/code/julia/Tree.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using DataStructures
22

3-
# This has not been implemented in your chosen language, so here's Julia code
43
struct Node
54
children::Vector{Node}
65
ID::Int64
76
Node(ID::Int64) = new(Vector{Node}(), ID)
87
end
98

10-
# This has not been implemented in your chosen language, so here's Julia code
119
function DFS_recursive(n::Node)
1210
# Here we are doing something...
1311
println(n.ID)
@@ -17,7 +15,6 @@ function DFS_recursive(n::Node)
1715
end
1816
end
1917

20-
# This has not been implemented in your chosen language, so here's Julia code
2118
function DFS_recursive_postorder(n::Node)
2219

2320
for child in n.children
@@ -28,7 +25,6 @@ function DFS_recursive_postorder(n::Node)
2825
println(n.ID)
2926
end
3027

31-
# This has not been implemented in your chosen language, so here's Julia code
3228
# This assumes only 2 children
3329
function DFS_recursive_inorder_btree(n::Node)
3430

@@ -46,7 +42,6 @@ function DFS_recursive_inorder_btree(n::Node)
4642
end
4743
end
4844

49-
# This has not been implemented in your chosen language, so here's Julia code
5045
function DFS_stack(n::Node)
5146
s = Stack(Node)
5247
push!(s, n)
@@ -60,7 +55,6 @@ function DFS_stack(n::Node)
6055
end
6156
end
6257

63-
# This has not been implemented in your chosen language, so here's Julia code
6458
function BFS_queue(n::Node)
6559
q = Queue(Node)
6660
enqueue!(q, n)
@@ -102,7 +96,6 @@ function main()
10296

10397
println("Using queue-based BFS:")
10498
BFS_queue(root);
105-
10699
end
107100

108101
main()

chapters/tree_traversal/code/julia/Tree_example.jl

Lines changed: 0 additions & 102 deletions
This file was deleted.

chapters/tree_traversal/tree_traversal.md

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ Trees are naturally recursive data structures, and because of this, we cannot ac
44

55
{% method %}
66
{% sample lang="jl" %}
7-
[import:4-8, lang:"julia"](code/julia/Tree.jl)
7+
[import:3-7, lang:"julia"](code/julia/Tree.jl)
88
{% sample lang="cpp" %}
99
[import:15-18, lang:"c_cpp"](code/c++/tree_example.cpp)
1010
{% sample lang="cs" %}
1111
[import:11-15, lang:"csharp"](code/cs/TreeMdAdditional/TreeMdAdditional.cs)
1212
{% sample lang="c" %}
1313
[import:5-10, lang:"c_cpp"](code/c/tree_traversal.c)
1414
{% sample lang="js" %}
15-
[import:3-8, lang:"julia"](code/julia/Tree.jl)
15+
This has not been implemented in your chosen language, so here is the Julia code
16+
[import:3-7, lang:"julia"](code/julia/Tree.jl)
1617
{% sample lang="py2" %}
1718
[import:1-5, lang:"python"](code/python2/Tree_example.py)
1819
{% sample lang="py3" %}
1920
[import:5-10, lang:"python"](code/python3/Tree_example.py)
2021
{% sample lang="scratch" %}
21-
[import:3-8, lang:"julia"](code/julia/Tree.jl)
22+
This has not been implemented in your chosen language, so here is the Julia code
23+
[import:3-7, lang:"julia"](code/julia/Tree.jl)
2224
{% sample lang="rs"%}
2325
[import:4-7, lang:"rust"](code/rust/tree.rs)
2426
{% endmethod %}
@@ -27,7 +29,7 @@ Because of this, the most straightforward way to traverse the tree might be recu
2729

2830
{% method %}
2931
{% sample lang="jl" %}
30-
[import:11-18, lang:"julia"](code/julia/Tree.jl)
32+
[import:9-16, lang:"julia"](code/julia/Tree.jl)
3133
{% sample lang="cpp" %}
3234
[import:20-27, lang:"c_cpp"](code/c++/tree_example.cpp)
3335
{% sample lang="cs" %}
@@ -39,9 +41,11 @@ Because of this, the most straightforward way to traverse the tree might be recu
3941
{% sample lang="py2" %}
4042
[import:8-16, lang:"python"](code/python2/Tree_example.py)
4143
{% sample lang="py3" %}
42-
[import:10-18, lang:"julia"](code/julia/Tree.jl)
44+
This has not been implemented in your chosen language, so here is the Julia code
45+
[import:9-16, lang:"julia"](code/julia/Tree.jl)
4346
{% sample lang="scratch" %}
44-
[import:10-18, lang:"julia"](code/julia/Tree.jl)
47+
This has not been implemented in your chosen language, so here is the Julia code
48+
[import:9-16, lang:"julia"](code/julia/Tree.jl)
4549
{% sample lang="rs"%}
4650
[import:9-15 lang:"rust"](code/rust/tree.rs)
4751
{% endmethod %}
@@ -59,23 +63,30 @@ Now, in this case the first element searched through is still the root of the tr
5963

6064
{% method %}
6165
{% sample lang="jl" %}
62-
[import:21-29, lang:"julia"](code/julia/Tree.jl)
66+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
6367
{% sample lang="cpp" %}
64-
[import:20-29, lang:"julia"](code/julia/Tree.jl)
68+
This has not been implemented in your chosen language, so here is the Julia code
69+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
6570
{% sample lang="cs" %}
6671
[import:75-84, lang:"csharp"](code/cs/TreeMdAdditional/TreeMdAdditional.cs)
6772
{% sample lang="c" %}
68-
[import:20-29, lang:"julia"](code/julia/Tree.jl)
73+
This has not been implemented in your chosen language, so here is the Julia code
74+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
6975
{% sample lang="js" %}
70-
[import:20-29, lang:"julia"](code/julia/Tree.jl)
76+
This has not been implemented in your chosen language, so here is the Julia code
77+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
7178
{% sample lang="py2" %}
72-
[import:20-29, lang:"julia"](code/julia/Tree.jl)
79+
This has not been implemented in your chosen language, so here is the Julia code
80+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
7381
{% sample lang="py3" %}
74-
[import:20-29, lang:"julia"](code/julia/Tree.jl)
82+
This has not been implemented in your chosen language, so here is the Julia code
83+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
7584
{% sample lang="scratch" %}
76-
[import:20-29, lang:"julia"](code/julia/Tree.jl)
85+
This has not been implemented in your chosen language, so here is the Julia code
86+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
7787
{% sample lang="rs"%}
78-
[import:20-29, lang:"julia"](code/julia/Tree.jl)
88+
This has not been implemented in your chosen language, so here is the Julia code
89+
[import:18-26, lang:"julia"](code/julia/Tree.jl)
7990
{% endmethod %}
8091

8192
<p align="center">
@@ -86,23 +97,30 @@ In this case, the first node visited is at the bottom of the tree and moves up t
8697

8798
{% method %}
8899
{% sample lang="jl" %}
89-
[import:32-47, lang:"julia"](code/julia/Tree.jl)
100+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
90101
{% sample lang="cpp" %}
91-
[import:31-47, lang:"julia"](code/julia/Tree.jl)
102+
This has not been implemented in your chosen language, so here is the Julia code
103+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
92104
{% sample lang="cs" %}
93105
[import:86-104, lang:"csharp"](code/cs/TreeMdAdditional/TreeMdAdditional.cs)
94106
{% sample lang="c" %}
95-
[import:31-47, lang:"julia"](code/julia/Tree.jl)
107+
This has not been implemented in your chosen language, so here is the Julia code
108+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
96109
{% sample lang="js" %}
97-
[import:31-47, lang:"julia"](code/julia/Tree.jl)
110+
This has not been implemented in your chosen language, so here is the Julia code
111+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
98112
{% sample lang="py2" %}
99-
[import:31-47, lang:"julia"](code/julia/Tree.jl)
113+
This has not been implemented in your chosen language, so here is the Julia code
114+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
100115
{% sample lang="py3" %}
101-
[import:31-47, lang:"julia"](code/julia/Tree.jl)
116+
This has not been implemented in your chosen language, so here is the Julia code
117+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
102118
{% sample lang="scratch" %}
103-
[import:31-47, lang:"julia"](code/julia/Tree.jl)
119+
This has not been implemented in your chosen language, so here is the Julia code
120+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
104121
{% sample lang="rs"%}
105-
[import:31-47, lang:"julia"](code/julia/Tree.jl)
122+
This has not been implemented in your chosen language, so here is the Julia code
123+
[import:28-43, lang:"julia"](code/julia/Tree.jl)
106124
{% endmethod %}
107125

108126
<p align="center">
@@ -123,7 +141,7 @@ In code, it looks like this:
123141

124142
{% method %}
125143
{% sample lang="jl" %}
126-
[import:50-61, lang:"julia"](code/julia/Tree.jl)
144+
[import:45-56, lang:"julia"](code/julia/Tree.jl)
127145
{% sample lang="cpp" %}
128146
[import:29-45, lang:"c_cpp"](code/c++/tree_example.cpp)
129147
{% sample lang="cs" %}
@@ -139,7 +157,8 @@ In code, it looks like this:
139157
{% sample lang="py3" %}
140158
[import:31-45, lang:"python"](code/python3/Tree_example.py)
141159
{% sample lang="scratch" %}
142-
[import:49-61, lang:"julia"](code/julia/Tree.jl)
160+
This has not been implemented in your chosen language, so here is the Julia code
161+
[import:45-56, lang:"julia"](code/julia/Tree.jl)
143162
{% sample lang="rs"%}
144163
[import:17-24, lang:"rust"](code/rust/tree.rs)
145164
{% endmethod %}
@@ -154,7 +173,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
154173

155174
{% method %}
156175
{% sample lang="jl" %}
157-
[import:64-75, lang:"julia"](code/julia/Tree.jl)
176+
[import:58-69, lang:"julia"](code/julia/Tree.jl)
158177
{% sample lang="cpp" %}
159178
[import:47-61, lang:"c_cpp"](code/c++/tree_example.cpp)
160179
{% sample lang="cs" %}
@@ -168,7 +187,8 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
168187
{% sample lang="py3" %}
169188
[import:48-62, lang:"python"](code/python3/Tree_example.py)
170189
{% sample lang="scratch" %}
171-
[import:63-75, lang:"julia"](code/julia/Tree.jl)
190+
This has not been implemented in your chosen language, so here is the Julia code
191+
[import:58-69, lang:"julia"](code/julia/Tree.jl)
172192
{% sample lang="rs"%}
173193
[import:26-34, lang:"rust"](code/rust/tree.rs)
174194
{% endmethod %}
@@ -177,7 +197,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
177197
{% method %}
178198
{% sample lang="jl" %}
179199
### Julia
180-
[import, lang:"julia"](code/julia/Tree_example.jl)
200+
[import, lang:"julia"](code/julia/Tree.jl)
181201
{% sample lang="cpp" %}
182202
### C++
183203
[import, lang:"c_cpp"](code/c++/tree_example.cpp)

0 commit comments

Comments
 (0)