当前位置: 首页>>代码示例>>Python>>正文


Python BST.inorder方法代码示例

本文整理汇总了Python中bst.BST.inorder方法的典型用法代码示例。如果您正苦于以下问题:Python BST.inorder方法的具体用法?Python BST.inorder怎么用?Python BST.inorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bst.BST的用法示例。


在下文中一共展示了BST.inorder方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_new_tree

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
def test_new_tree():
    from bst import BST
    new_bst = BST()
    new_bst.insert(100)
    new_bst.insert(25)
    new_bst.insert(30)
    new_bst.insert(40)
    assert [x for x in new_bst.inorder(new_bst.head)] == [25, 30, 40, 100]
开发者ID:palindromed,项目名称:data-structures2,代码行数:10,代码来源:test_bst.py

示例2: test_inorder

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
def test_inorder():
    nums = range(1, 200)
    random.shuffle(nums)
    bst = BST()
    for n in nums:
        bst.add(n)
    nums.sort()

    assert bst.inorder() == sorted(nums)
开发者ID:johncip,项目名称:data_structures,代码行数:11,代码来源:test_bst.py

示例3: bstsort

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
def bstsort(l):
    arbol = BST()
    # Generamos nuestra estructura 
    # de datos auxiliar
    
    while l:
        # Vaciamos la lista en el arbol
        item = l.pop()
        arbol.add(item)
    
    l.extend(arbol.inorder())
开发者ID:RatasRecursivas,项目名称:bstsort,代码行数:13,代码来源:bstsort.py

示例4: sorted_array_to_bst

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
from bst import BST, Node

def sorted_array_to_bst(array):
	return _sorted_array_to_bst(array, 0, len(array)-1)

def _sorted_array_to_bst(array, left, right):
	if left == right:
		return Node(array[left])
	if left > right:
		return None

	mid = (left + right) / 2
	root = Node(array[mid])
	root.left = _sorted_array_to_bst(array, left, mid-1)
	root.right = _sorted_array_to_bst(array, mid+1, right)
	return root

if __name__ == "__main__":
	array = [0, 1, 2, 3, 4, 5]
	tree = BST(sorted_array_to_bst(array))
	tree.inorder()
开发者ID:kmavila,项目名称:coding-interview-questions,代码行数:23,代码来源:sorted_array_to_bst.py

示例5: createConcordance

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
def createConcordance(inputFile, stopWords, outputFile):

    #declare data structures
    stopSet = HashSet(3500)
    dictionary = HashDictionary(10000)
    bst = BST()

    #declare regular expressions
    newLine = re.compile(r'\n')
    exprSpaces = re.compile(r'\s')
    dhyp = re.compile('--')
    notChars = re.compile('\W|-')
    
    #populate hashset with stop words
    stopWords = open(stopWords, 'r')
    for stop in stopWords:
        x = newLine.search(stop)
        stop = stop[:x.start()]
        if stop == "":
            break
        stopSet.add(stop)
    stopWords.close()
    
    #open the input and process into words
    f = open(inputFile, 'r')
    lineNum = 0
    while True:
        line = f.readline()
        lineNum += 1
        if line == "":
            break

        #split lines
        m = dhyp.split(line)
        alist = []
        for i in range(len(m)):
            g = exprSpaces.split(m[i])
            alist = alist + g
            
        #strip down to words
        print alist
        for word in alist:
            if word == None:
                pass
            else:
                word = string.lower(word)
                while True:
                    n = notChars.search(word)
                    if len(word) <= 0:
                        break
                    elif n != None:
                        if n.start() == 0:
                            word = word[n.end():]
                        else:
                            word = word[:n.start()]
                    else:
                        break
                            
                #check if word is stop word
                if not stopSet.contains(word) and len(word) > 0:
                    #if word isn't already in dictionary
                    if dictionary.search(word) == None:
                        linkedValue = LinkedIndexedList()
                        dictionary.store(word, linkedValue)
                        dictionary.search(word).append(lineNum)
                        bst.add(word)
                    #if the word is in the dictionary
                    else:
                        dictionary.search(word).append(lineNum)
    f.close()

    #open output and use BST to print out words
    #   in alphabetical order
    output = open(outputFile, 'w')
    lyst = bst.inorder()
    temp = None
    for item in lyst:
        temp = dictionary.search(item)
        output.write(item + " - " + str(temp)+"\n")
    output.close()
开发者ID:cartothemax,项目名称:computer-science-two-coursework,代码行数:82,代码来源:pa08.py

示例6: Node

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
from bst import BST
from bst import Node

if __name__ == "__main__":
	root = Node(5)
	bst = BST()
	bst.insert(root, Node(2))
	bst.insert(root, Node(3))
	bst.insert(root, Node(4))
	print "Inorder traversal"
	bst.inorder(root)
	print "Preorder traversal"
	bst.preorder(root)
	print "Postorder traversal"
	bst.postorder(root)
开发者ID:ronakmshah,项目名称:playground,代码行数:17,代码来源:_bst-insert-traversal.py

示例7: test_init_list

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
def test_init_list():
    nums = range(0, 10)
    t = BST(keys=nums)
    assert t.inorder() == nums
开发者ID:johncip,项目名称:data_structures,代码行数:6,代码来源:test_bst.py

示例8: test_init_empty

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
def test_init_empty():
    t = BST()
    assert t.inorder() == []
开发者ID:johncip,项目名称:data_structures,代码行数:5,代码来源:test_bst.py

示例9: test_unique_queue

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import inorder [as 别名]
def test_unique_queue():
    BST(keys=[1])
    t = BST(keys=[2])
    assert t.inorder() == [2]
开发者ID:johncip,项目名称:data_structures,代码行数:6,代码来源:test_bst.py


注:本文中的bst.BST.inorder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。