[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/feichenxue/algorithm/master/binary_tree2.py [Back]  [Original]

#! /usr/bin/env python
#coding:utf-8

# The code is from:http://code.activestate.com/recipes/286239-binary-ordered-tree/
# A binary ordered tree example

class CNode:
    left , right, data = None, None, 0
    
    def __init__(self, data):
        # initializes the data members
        self.left = None
        self.right = None
        self.data = data

        
class CBOrdTree:
    def __init__(self):
        # initializes the root member
        self.root = None
        
    def addNode(self, data):
        # creates a new node and returns it
        return CNode(data)
            
    def insert(self, root, data):
        # inserts a new data
        if root == None:
            # it there isn't any data
            # adds it and returns
            return self.addNode(data)
        else:
            # enters into the tree
            if data 

Web Proxy Viewer  |  New URL  |  Original Page