Closed abhinavsp0730 closed 3 years ago
@abhinavsp0730 Can you please explain it with an example?
def inorder(root):
#base case: when we reach the leaf node
if not root:
return
#traversing left subtree recursively
inorder(root.left)
#printing the root val
print(root.val)
#traversing right subtree recursively
inorder(root.right)
This is the function for inorder traversal of a binary tree at each recursive function call I'm printing the current node value. So, I want to add whatever I'm prininting in the animation.
There is no direct way of adding standard output to the animations of now since we are simply executing the function and drawing an edge between the caller and the called function.
What you are trying to do is can be achieved by using more low level graph librray pydot
directly, which this library uses. What you can do is write logic to draw node and edges only when the code execution reaches the print keyword.
But I wonder what kind of graph you are looking for i.e where you want to print the root.val
.
I think the better way to visualize such kind of traversal is you have a BT beforehand and what you can do is visualize the path(maybe highlight node and edges). Currently there is no way to do this with recursion-visualiser
as we are simply tracing the call. You may need some animation library or write your custom logic using pydot
, networkx
or any graphing library,
Closing the issue for now. In the meantime you can checkout https://github.com/mapio/GraphvizAnim which I think meets your requirements.
Thanks @Bishalsarang . Would you please tell me why return value hasn't been shown in the gif?
Since we are not returning anything return value is not shown. See the examples section for reference. We are constructing the result using return value from intermediate function.
For above case we are making the recursive call, but we are not using return value of any call. Hope that answers your question.
No, I'm talking about a new code. I'm getting return value in the generated pic but it's not showing in the generated gif.
On Thu, Aug 19, 2021, 12:29 PM Bishal Sarangkoti @.***> wrote:
Since we are not returning anything return value is not shown. See the examples section for reference. We are constructing the result using return value from intermediate function.
For above case we are making the recursive call, but we are not using return value of any call. Hope that answers your question.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Bishalsarang/Recursion-Tree-Visualizer/issues/23#issuecomment-901660128, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKM6BK6LPCQUMW5BZQQH6XLT5STUXANCNFSM5CEYMAHA .
Can you post the code and both gifs and png? I'll have a look.
Can we create animation of std out in every function call?