recursion - Simple c++ recursive explaination needed -
I am currently trying to wrap my head around recursive, so I picked up the C ++ textbook and started reading It was easy to understand the first page of the chapter on recapitulation, but then I found an item which was not understood for me. Returns the integer height (node * p) {if (p == NULL);
; Other {return 1+ max (height (p-; lynch), height (p-> arlink)); } If maximum gives me the highest quality of two values, then what is the maximum argument for which it is returning at the height. If someone can help me then I would appreciate it ...
Recurring Recurring Recurring:
- You can understand that the height of an empty tree is 0
- You can understand that the height of generic non-empty tree is 1+ longest subtitle The height of which can be started from left or right side)
From the beginning, you can degrade the code if you attract the tree, you will see What happens is that. If you have a / bc / dee -
height (a) will return for example 1 + maximum (height (b), height (c)) -
height (b) back 1+ max (d), height ( E)) -
height (C) back 1 + maximum (height (zero), height (zero)) = 1 < / Li> -
height (d) back 1 + maximum (height (zero), height (zero)) = 1 -
Height (E) back 1 + maximum (height (height), height (zero)) = 1 Height (A) = 1 + maximum (height (B), height (C)) = = 1 + maximum (1 + maximum (height (D), height (E) ) , 1) = = 1 + maximum (1 + 1, 1) = 1 + maximum (2, 1) = 3 (I have height (zero) Because they are trivial 0 and otherwise it would be too much vocabulary.)
Comments
Post a Comment