Skip to content
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

Binary Tree #119

Closed
waddlaw opened this issue Jul 10, 2018 · 0 comments
Closed

Binary Tree #119

waddlaw opened this issue Jul 10, 2018 · 0 comments

Comments

@waddlaw
Copy link
Contributor

waddlaw commented Jul 10, 2018

#113 からの派生

definition

data Tree
  = Leaf Int
  | Node Tree Tree

-- より一般化したもの
data Tree a
  = Leaf a
  | Node (Tree a) (Tree a)

operation

-- 部分木を左右反転させた木を返す
mirror :: Tree a -> Tree a

-- 葉の数を返す
count :: Tree a -> Int

-- 木の高さを返す
depth :: Tree -> Int

-- 木が平衡かどうか
balanced :: Tree -> Bool

-- 葉の値を集めてリストにして返す
leaves :: Tree a -> [a]

-- 左の部分木を返す
left :: Tree a -> Maybe (Tree a)

-- 右の部分木を返す
right :: Tree a -> Maybe (Tree a)

reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant