किताबों के शीर्षक वर्णानुक्रम में प्रिंट करना
इस वीडियो में आपने depth first search traversal को binary trees पर लागू करने के तीन तरीके सीखे: in-order, pre-order, और post-order.
निम्न binary search tree में कुछ किताबों के शीर्षक स्टोर किए गए हैं.

यह tree bst वैरिएबल (पंक्ति 15) में पहले से लोड किया गया है:
bst = CreateTree()
क्या आप in-order traversal लगा सकते हैं ताकि किताबों के शीर्षक वर्णानुक्रम में दिखाई दें?
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Data Structures और Algorithms
अभ्यास निर्देश
- जाँचें कि
current_nodeमौजूद है या नहीं. - पेड़ के उपयुक्त हिस्से पर
in_order()फंक्शन को recursively कॉल करें. current_nodeका मान प्रिंट करें.- पेड़ के दूसरे हिस्से पर
in_order()फंक्शन को recursively कॉल करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
class BinarySearchTree:
def __init__(self):
self.root = None
def in_order(self, current_node):
# Check if current_node exists
if ____:
# Call recursively with the appropriate half of the tree
self.in_order(current_node.____)
# Print the value of the current_node
print(____)
# Call recursively with the appropriate half of the tree
self.in_order(current_node.____)
bst = CreateTree()
bst.in_order(bst.root)