BaşlayınÜcretsiz Başlayın

Correcting bugs in a tree implementation

You have been given a program that is supposed to create the following binary tree:

Graphical representation of a tree.

Testing it, you realize that the program is not correct. Could you correct it so that it works correctly?

Bu egzersiz

Data Structures and Algorithms in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Correct the mistakes in the init() method.
  • Correct the mistake in the creation of the root_node.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

class TreeNode:
  
  def __init__(self, data, left=None, right=None):
    # Correct the mistakes
    self.data = None
    self.left_child = None
    self.right_child = None

node1 = TreeNode("B")
node2 = TreeNode("C")
# Correct the mistake
root_node = TreeNode(node1, node2, "A")
Kodu Düzenle ve Çalıştır