Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nesteiner/binarytree.jl
二叉树 written in Julia
https://github.com/nesteiner/binarytree.jl
Last synced: about 2 months ago
JSON representation
二叉树 written in Julia
- Host: GitHub
- URL: https://github.com/nesteiner/binarytree.jl
- Owner: nesteiner
- Created: 2023-04-09T08:23:38.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-10T16:38:41.000Z (almost 2 years ago)
- Last Synced: 2024-04-09T22:38:47.139Z (10 months ago)
- Language: Julia
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
#+title: BinaryTree in Julia
* BinaryTree
** Attenion
不要使用 UnionAll 的泛型
** Create
*** BSTree
#+begin_src julia
tree = BSTree(Int)
#+end_src
*** AVLTree
#+begin_src julia
tree = AVLTree(Int)
#+end_src
** Operation
*** insert!
#+begin_src julia
for i in 1:50
insert!(tree, i)
end
#+end_src
*** popat!
#+begin_src julia
popat!(tree, value)
#+end_src
*** length
#+begin_src julia
length(tree)
#+end_src
*** traveral
**** levelorder
#+begin_src julia
for node in levelorder(tree)
println(dataof(node))
end
#+end_src
**** preorder
#+begin_src julia
for node in preorder(tree)
println(dataof(node))
end
#+end_src
**** inorder
#+begin_src julia
for node in inorder(tree)
println(dataof(node))
end
#+end_src
**** postorder
#+begin_src julia
for node in postorder(tree)
println(dataof(node))
end
#+end_src
*** search
#+begin_src julia
node = search(tree, 10)
#+end_src
*** contains
#+begin_src julia
contains(tree, 10) # true
contains(tree, -1) # false
#+end_src
*** findfirst
#+begin_src julia
node = findfirst(isequal(50), tree)
#+end_src
*** replace!
#+begin_src julia
node = findfirst(isequal(50), tree)
if !isnothing(node)
replace!(node, -50)
end
#+end_src
*** 函数式
**** filter
#+begin_src julia
filter(x -> x % 2 == 0, tree)
#+end_src
**** map
#+begin_src julia
array = map(x -> x + 1, tree)
#+end_src
**** reduce
#+begin_src julia
reduce(+, tree)
#+end_src