Skip to content

Removing useless code in tree traversal. #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions chapters/tree_traversal/code/julia/Tree.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using DataStructures

# This has not been implemented in your chosen language, so here's Julia code
struct Node
children::Vector{Node}
ID::Int64
Node(ID::Int64) = new(Vector{Node}(), ID)
end

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

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

for child in n.children
Expand All @@ -28,7 +25,6 @@ function DFS_recursive_postorder(n::Node)
println(n.ID)
end

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

Expand All @@ -46,7 +42,6 @@ function DFS_recursive_inorder_btree(n::Node)
end
end

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

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

println("Using queue-based BFS:")
BFS_queue(root);

end

main()
102 changes: 0 additions & 102 deletions chapters/tree_traversal/code/julia/Tree_example.jl

This file was deleted.

74 changes: 47 additions & 27 deletions chapters/tree_traversal/tree_traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ Trees are naturally recursive data structures, and because of this, we cannot ac

{% method %}
{% sample lang="jl" %}
[import:4-8, lang:"julia"](code/julia/Tree.jl)
[import:3-7, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
[import:15-18, lang:"c_cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
[import:11-15, lang:"csharp"](code/cs/TreeMdAdditional/TreeMdAdditional.cs)
{% sample lang="c" %}
[import:5-10, lang:"c_cpp"](code/c/tree_traversal.c)
{% sample lang="js" %}
[import:3-8, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:3-7, lang:"julia"](code/julia/Tree.jl)
{% sample lang="py2" %}
[import:1-5, lang:"python"](code/python2/Tree_example.py)
{% sample lang="py3" %}
[import:5-10, lang:"python"](code/python3/Tree_example.py)
{% sample lang="scratch" %}
[import:3-8, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:3-7, lang:"julia"](code/julia/Tree.jl)
{% sample lang="rs"%}
[import:4-7, lang:"rust"](code/rust/tree.rs)
{% endmethod %}
Expand All @@ -27,7 +29,7 @@ Because of this, the most straightforward way to traverse the tree might be recu

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

{% method %}
{% sample lang="jl" %}
[import:21-29, lang:"julia"](code/julia/Tree.jl)
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
[import:20-29, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cs" %}
[import:75-84, lang:"csharp"](code/cs/TreeMdAdditional/TreeMdAdditional.cs)
{% sample lang="c" %}
[import:20-29, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="js" %}
[import:20-29, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="py2" %}
[import:20-29, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="py3" %}
[import:20-29, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="scratch" %}
[import:20-29, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="rs"%}
[import:20-29, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% endmethod %}

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

{% method %}
{% sample lang="jl" %}
[import:32-47, lang:"julia"](code/julia/Tree.jl)
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
[import:31-47, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cs" %}
[import:86-104, lang:"csharp"](code/cs/TreeMdAdditional/TreeMdAdditional.cs)
{% sample lang="c" %}
[import:31-47, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="js" %}
[import:31-47, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="py2" %}
[import:31-47, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="py3" %}
[import:31-47, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="scratch" %}
[import:31-47, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="rs"%}
[import:31-47, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% endmethod %}

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

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

{% method %}
{% sample lang="jl" %}
[import:64-75, lang:"julia"](code/julia/Tree.jl)
[import:58-69, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
[import:47-61, lang:"c_cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
Expand All @@ -168,7 +187,8 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
{% sample lang="py3" %}
[import:48-62, lang:"python"](code/python3/Tree_example.py)
{% sample lang="scratch" %}
[import:63-75, lang:"julia"](code/julia/Tree.jl)
This has not been implemented in your chosen language, so here is the Julia code
[import:58-69, lang:"julia"](code/julia/Tree.jl)
{% sample lang="rs"%}
[import:26-34, lang:"rust"](code/rust/tree.rs)
{% endmethod %}
Expand All @@ -177,7 +197,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
{% method %}
{% sample lang="jl" %}
### Julia
[import, lang:"julia"](code/julia/Tree_example.jl)
[import, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
### C++
[import, lang:"c_cpp"](code/c++/tree_example.cpp)
Expand Down