开发者

When should a tree structure be class/struct?

开发者 https://www.devze.com 2023-01-25 18:00 出处:网络
What are the criteria on which to开发者_Python百科 decide when a tree node should be a struct or a class?i would go for class becuase you can pass node as reference but not on the struct which will be

What are the criteria on which to开发者_Python百科 decide when a tree node should be a struct or a class?


i would go for class becuase you can pass node as reference but not on the struct which will be passed as a copy of original

and you would require a lot of manupulation on nodes so passing them as a reference sometime results in performance boostup.

and if you are storing a lot of data in the your node tahn struct would not be a choice.

i am not pointing out which is more faster value or refernce types that totally depends on scenarios.


Structs are usually more lightweight and are considered value types. Classes are reference types.

Consider this post also: Which is best for data store Struct/Classes?


While modifying the tree, you need at least 2 pointers/references to the same "data", this is hard to do with structs, unless you box (convert to object) them explicitly.

0

精彩评论

暂无评论...
验证码 换一张
取 消