gyuho / learn

learn
https://gyuho.dev
Other
1.31k stars 154 forks source link

Inserting a value vs. a *Node #81

Closed jutkko closed 7 years ago

jutkko commented 7 years ago

Hi I love this repo! I am going through it and I have a question to ask. Here https://github.com/gyuho/learn/blob/master/doc/binary_search_tree/code/00_insert.go#L62, why did you choose to make the insert function take a *Node? Since the pointer to the element can be changed, wouldn't this break the binary search tree?

gyuho commented 7 years ago

Because every node in binary tree is pointer in my implementation. You could implement it just by passing value (int, string, etc.). If you concern about manipulating the node before inserting, you can change your implementation to value :)