Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

alberi binari di ricerca python

class Node:
    def __init__(self, value=None, left=None, right=None):
        self.left = None
        self.right = None
        self.value = value

    def insertValue(self, value):
        if not self.value:
            self.value = value
            return
        if self.value == value:
            return
        if value < self.value:
            if self.left:
                self.left.insertValue(value)
                return
            self.left = Node(value)
            return
        if self.right:
            self.right.insertValue(value)
            return
        self.right = Node(value)

    def getMin(self):
        while self.left is not None:
            self = self.left
        return self.value

    def getMax(self):
        while self.right is not None:
            self = self.right
        return self.value

def buildABR(lista):
    bst = Node()
    for x in lista:
        bst.insertValue(x)
    return bst

if __name__ == "__main__":
    lista = [99, 6, 18, -1, 21, 11, 3, 5, 4, 24, 18]
    abr = buildABR(lista)
    print(abr.getMax())
    print(abr.getMin())
Comment

PREVIOUS NEXT
Code Example
Python :: django force download file 
Python :: convert a column to camel case in python 
Python :: string float to round to 2dp python 
Python :: python last element of list using reverse() function 
Python :: python paragraph Pypi 
Python :: multiply two list in python using lambda 
Python :: mechanize python XE #28 
Python :: pseudo-random input signal python 
Python :: form list of filename get the filename with highest num pythn 
Python :: django rest DjangoModelPermissions include get 
Python :: iterate 
Python :: generate jwt token just passing userid in rest_framework_simplejwt 
Python :: install python3 yum centOS redhat 
Python :: pyqt grid layout 
Python :: plotly dcc.interval bar graph with time 
Python :: clear terminal anaconda 
Python :: python deconstruct tuple 
Python :: flassger 
Python :: custom port odoo 
Python :: Command to install Voluptuous Python Library 
Python :: online c compiler and exe file 
Python :: glom safely interact with dictionary 
Python :: python set vs tuple performance 
Python :: to iterate across information on same nest 
Python :: python evenly spaced integers 
Python :: Python NumPy moveaxis function Example 02 
Python :: python dictionary examples 
Python :: Python NumPy row_stack Function Syntax 
Python :: how to add to an exsiting value of an index in a list 
Python :: how to fetch limited rows in pandas dataframe using sqlalchemy 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =