Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Trying to learn about Binary Tree while preparing for an exam, and I came across this code. And even tho it looks like it makes sense I simply cannot understand the purpose of this and how it actually works, so can anyone please elaborate?



And this is the code :

space += 5;

print_tree(root->right, space);

printf("\n");
for (int i = 5; i number);

print_tree(root->left, space);

What I have tried:

this is the result I get : https://i.ibb.co/3TTjJBr/kkkkkkkkkkkkj.jpg
Posted
Updated 25-Aug-19 21:11pm
Comments
Richard MacCutchan 26-Aug-19 3:40am    
That code will not even compile and makes no sense, and the link is broken.
higii 26-Aug-19 5:23am    
hey, this is just one part of the code that was unclear to me and that's why I posted this question. Anyway, someone just gave me the answer :

"It basically prints out the tree starting from the right side.. And it adds blank spaces based on how far in you are so it displays like that in the console.. So 55 is deeper by one from 33 so it has 5 more spaces in front of it and so on."
Richard MacCutchan 26-Aug-19 5:45am    
OK, so update your question and explain what the problem is.
Patrice T 26-Aug-19 4:51am    
this code makes no sense!
Show code that can be compiled
Stefan_Lang 29-Aug-19 4:23am    
The for statement is not valid code. Even if you fix the syntax, the fact that it ends with a ; means it's not doing anything at all. Are you sure you haven't accidentally cut out parts of the code?

As for the calls to the print_tree() function, we can only guess what it does, especially regarding the second parameter. Without any more code we just can't know.

Regarding the result, if you think it's useful, copy the printed result as text. Don't post links. Following a link to an unknown source requires trust that some may not be willing to grant to strangers. Links are ok if they go to known sources, such as Wikipedia.

In short, with as little information as you gave us, there's nothing we can do to help you understand that code.

That said, the ability to understand another person's code is useful, but not necessarily helpful in understanding the underlying concepts. It would be more efficient to learn the concepts directly from a reliable source or tutorial (see solution 1).

1 solution

 
Share this answer
 
v2
Comments
higii 26-Aug-19 3:19am    
Hey, thanks for that tutorial. I checked it out a bit and it kinda seems a bit too advanced for me. They explain the basics but then just post a long code without proper explanation so I think I'll get lost by the looks of it.
RickZeeland 26-Aug-19 4:41am    
No one said a programmers life would be easy :)
Stefan_Lang 29-Aug-19 4:25am    
It's much more efficient to learn the concepts from a reliable source than from some program that, more likely than not, didn't spend a lot of effort making the code - and it's underlying concepts - understandable for others!

If you think that tutorial is hard, I'll tell you that learning it from existing code that isn't meant as a tutorial will be much harder!
RickZeeland 29-Aug-19 6:40am    
You have a point there, but the question is "what is a reliable source" of course ...
Stefan_Lang 30-Aug-19 3:29am    
I'd have said 'more reliable', but every ant would have jumped *that* bar! ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900