From fb8d4a53873cf78a730fb7ae5bb7a1a3509db6f1 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Mon, 26 Sep 2016 02:52:05 +0530 Subject: [PATCH] changed named to binary tree traversals --- ...raversals.py => binary_tree_traversals.py} | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) rename traverals/{tree_traversals.py => binary_tree_traversals.py} (66%) diff --git a/traverals/tree_traversals.py b/traverals/binary_tree_traversals.py similarity index 66% rename from traverals/tree_traversals.py rename to traverals/binary_tree_traversals.py index e28f7bccfebe..4c60d5207f50 100644 --- a/traverals/tree_traversals.py +++ b/traverals/binary_tree_traversals.py @@ -77,20 +77,29 @@ def level_order(node): q.put(node_dequeued.right) -node = build_tree() +if __name__ == '__main__': + import sys + print("\n********* Binary Tree Traversals ************\n") + # For python 2.x and 3.x compatibility: 3.x has not raw_input builtin + # otherwise 2.x's input builtin function is too "smart" + if sys.version_info.major < 3: + input_function = raw_input + else: + input_function = input -print("\n********* Pre Order Traversal ************") -pre_order(node) -print("\n******************************************\n") + node = build_tree() + print("\n********* Pre Order Traversal ************") + pre_order(node) + print("\n******************************************\n") -print("\n********* In Order Traversal ************") -in_order(node) -print("\n******************************************\n") + print("\n********* In Order Traversal ************") + in_order(node) + print("\n******************************************\n") -print("\n********* Post Order Traversal ************") -post_order(node) -print("\n******************************************\n") + print("\n********* Post Order Traversal ************") + post_order(node) + print("\n******************************************\n") -print("\n********* Level Order Traversal ************") -level_order(node) -print("\n******************************************\n") + print("\n********* Level Order Traversal ************") + level_order(node) + print("\n******************************************\n")