Code icon

The App is Under a Quick Maintenance

We apologize for the inconvenience. Please come back later

Menu iconMenu iconAlgorithms and Data Structures with Python
Algorithms and Data Structures with Python

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()