#help!! with inserting multiple values in a tree using recursion via constructor
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Define constructor for inserting multiple values at once! ‘’’ node(int x, node* next): data(x), next(next) {}
My favourite is define a structure then keep on adding using this constructor!
If the next post in this thread isn’t a photo with the thumb partially covering the screen, I’ll be disappointed

Haven't tried this method before could you help me in using this with the help of using code that I've written
You just have to define your constructor in such a way that it takes first parameter as data, second parameter as left node (a pointer to your class or structure) and third parameter as your right node!
I’m travelling so can’t help you with much resource! Happy coding bro! 😁
There's a better way to do this, using initializer lists, the setup code becomes much smaller requiring way less new TreeNode commands:
Also, I'm using templates here to make this a more generic tree which can hold any type, but the design pattern is applicable without templates as well, you just need to make a constructor that takes two
TreeNode &for left and right, which then get constructed in place
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity