Exemplo n.º 1
0
def parseTwoBinaryTree(file):
    from DataStructure.Utils import arrayToBinaryTree
    for line in file:
        t1S, t2S = line.rstrip('\n').split('}, {')

        t1S = t1S[1:]
        t1NodeArray = t1S.split(',')
        if t1NodeArray[0] == '':
            t1NodeArray = []
        t1 = arrayToBinaryTree(t1NodeArray)

        t2S = t2S[:-1]
        t2NodeArray = t2S.split(',')
        if t2NodeArray[0] == '':
            t2NodeArray = []
        t2 = arrayToBinaryTree(t2NodeArray)
        yield t1, t2
Exemplo n.º 2
0
def parseBinaryTree(file):
    from DataStructure.Utils import arrayToBinaryTree
    for line in file:
        line = line.strip('{}\n')
        nodeArray = line.split(',')
        if nodeArray[0] == '':
            nodeArray = []
        root = arrayToBinaryTree(nodeArray)
        yield root,
Exemplo n.º 3
0
def parseBinaryTreeAndInt(file):
    from DataStructure.Utils import arrayToBinaryTree
    for line in file:
        arrayString, iString = line.split('}, ')
        i = int(iString.rstrip('\n'))
        array = arrayString.lstrip('{').split(',')
        if array[0] == '':
            array = []
        root = arrayToBinaryTree(array)
        yield root, i
Exemplo n.º 4
0
def parseBinaryTreeArray(file):
    from DataStructure.Utils import arrayToBinaryTree
    for line in file:
        line = line.strip('[{}]\n')
        array = []
        if line != '':
            bStringArray = line.split('},{')
            for s in bStringArray:
                a = []
                if s != '':
                    a = s.split(',')
                array.append(arrayToBinaryTree(a))
        yield array,