예제 #1
0
from BaseClass import BST
from BTreeAndBST import inorder
tree = BST()
tree.ins(tree.root,6)
tree.ins(tree.root,2)
tree.ins(tree.root,4)
tree.ins(tree.root,0)
tree.ins(tree.root,3)
tree.ins(tree.root,5)
tree.ins(tree.root,1)
tree.ins(tree.root,-1)

tree.ins(tree.root,8)
tree.ins(tree.root,7)
tree.ins(tree.root,10)
tree.ins(tree.root,9)
tree.ins(tree.root,11)
inorder(tree.root)
print "\n"

##N^2 complexity
def BSTDLL(x,flag):
    if x==None:
        return
    if x.left==None and x.right==None:
        return x
    l=None
    r=None
    if x.left:
        l = BSTDLL(x.left,'r')
    if x.right:
예제 #2
0
from BaseClass import BTree, BST
bTree = BTree()
bs = BST()
bTree.insertL(bTree.root, 2)
bTree.insertL(bTree.root, 3)
bTree.insertR(bTree.root, 4)
bTree.insertL(bTree.root, 5)
bTree.insertL(bTree.root, 6)
bTree.insertR(bTree.root, 7)

for i in range(10):
    bs.ins(bs.root, i)


def inorder(x):
    if x == None:
        return
    if x.left != None:
        inorder(x.left)
    print x
    if x.right != None:
        inorder(x.right)


def preorder(x):
    if x == None:
        return
    print x
    if x.left != None:
        preorder(x.left)
    elif x.right != None: