idiom#9 构造Btree

Create a Binary Tree data structure

Python

class Node:
    def __init__(self, data, left_child, right_child):
        self.data = data
        self._left_child = left_child
        self._right_child = right_child

class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

Rust

#![allow(unused)]
fn main() {
struct BinTree<T> {
    value: T,
    left: Option<Box<BinTree<T>>>,
    right: Option<Box<BinTree<T>>>,
}

}

Elixir

defmodule BinaryTree do
	defstruct data: nil, left: nil, right: nil
end

Humm?

和 Python 基本相似; 不过, Rust 明显有更多内建模块支持各种姿势的嗯哼...

  • ...
          _~∽~∽~_
      \/ /  = ◴  \ \/
        '_   ⎵   _'
        ( '-----' )

...act by ferris-actor v0.2.4 (built on 23.0303.201916)

知识共享许可协议 本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可;-)