You've learned this already. ✅
Click here to view the next lesson.
Project 2: Contact Book Application
Listing All Contacts
Finally, let's implement a functionality to list all contacts in alphabetical order, which can be achieved through an in-order traversal of the BST.
class ContactBookBST:
# ... previous methods ...
def in_order_traversal(self, root):
if root:
self.in_order_traversal(root.left)
print(f"{root.name}: {root.phone}, {root.email}")
self.in_order_traversal(root.right)
def list_contacts(self):
self.in_order_traversal(self.root)
# Example Usage
contact_book.list_contacts()
Listing All Contacts
Finally, let's implement a functionality to list all contacts in alphabetical order, which can be achieved through an in-order traversal of the BST.
class ContactBookBST:
# ... previous methods ...
def in_order_traversal(self, root):
if root:
self.in_order_traversal(root.left)
print(f"{root.name}: {root.phone}, {root.email}")
self.in_order_traversal(root.right)
def list_contacts(self):
self.in_order_traversal(self.root)
# Example Usage
contact_book.list_contacts()
Listing All Contacts
Finally, let's implement a functionality to list all contacts in alphabetical order, which can be achieved through an in-order traversal of the BST.
class ContactBookBST:
# ... previous methods ...
def in_order_traversal(self, root):
if root:
self.in_order_traversal(root.left)
print(f"{root.name}: {root.phone}, {root.email}")
self.in_order_traversal(root.right)
def list_contacts(self):
self.in_order_traversal(self.root)
# Example Usage
contact_book.list_contacts()
Listing All Contacts
Finally, let's implement a functionality to list all contacts in alphabetical order, which can be achieved through an in-order traversal of the BST.
class ContactBookBST:
# ... previous methods ...
def in_order_traversal(self, root):
if root:
self.in_order_traversal(root.left)
print(f"{root.name}: {root.phone}, {root.email}")
self.in_order_traversal(root.right)
def list_contacts(self):
self.in_order_traversal(self.root)
# Example Usage
contact_book.list_contacts()