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

fixed issue #4 and implemented matrix transpose function #20

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
postOrder and preOrder outputs changed
  • Loading branch information
pourya-momtaz committed Feb 4, 2021
commit e147fe5e09012d8b1b3e8cba0063785010ba7002
12 changes: 6 additions & 6 deletions data-structures/binary-tree/bst.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,28 @@ func IterOnTree(n *Node, f func(*Node)) bool {
return IterOnTree(n.Right, f)
}

func PreOrder(n *Node) []*Node {
var nodes []*Node
func PreOrder(n *Node) []int {
var nodes []int

if n == nil {
return nodes
}

nodes = append(nodes, n)
nodes = append(nodes, n.Value)
nodes = append(nodes, PreOrder(n.Left)...)
nodes = append(nodes, PreOrder(n.Right)...)
return nodes
}

func PostOrder(n *Node) []*Node {
var nodes []*Node
func PostOrder(n *Node) []int {
var nodes []int

if n == nil {
return nodes
}

nodes = append(nodes, PostOrder(n.Left)...)
nodes = append(nodes, PostOrder(n.Right)...)
nodes = append(nodes, n)
nodes = append(nodes, n.Value)
return nodes
}