Learn practical skills, build real-world projects, and advance your career

binary-search-tree-practice

Use the "Run" button to execute the code.

!pip install jovian --upgrade --quiet
import jovian
# Execute this to save new versions of the notebook
jovian.commit(project="binary-search-tree-practice")
class UserDatabase:
    def __init__(self):
        self.users = []
    
    def insert(self, user):
        i = 0
        while i < len(self.users):
            # Find the first username greater than the new user's username
            if self.users[i].username > user.username:
                break
            i += 1
        self.users.insert(i, user)
    
    def find(self, username):
        for user in self.users:
            if user.username == username:
                return user
    
    def update(self, user):
        target = self.find(user.username)
        print(target)
        if target != None:
            target.name, target.email = user.name, user.email
        
    def list_all(self):
        return self.users