示例#1
0
文件: Parser.py 项目: yanh/pyshua
def parseTwoSingleLinkedList(file):
    from DataStructure.Utils import arrayToSingleLinkedList
    for line in file:
        a1, a2 = line.split('}, {')
        a1 = a1.lstrip('{')
        if a1 == '':
            l1 = None
        else:
            l1 = arrayToSingleLinkedList([int(x) for x in a1.split(',')])

        a2 = a2.rstrip('}\n')
        if a2 == '':
            l2 = None
        else:
            l2 = arrayToSingleLinkedList([int(x) for x in a2.split(',')])
        yield l1, l2
示例#2
0
文件: Parser.py 项目: yanh/pyshua
def parseSingleLinkedList(file):
    from DataStructure.Utils import arrayToSingleLinkedList
    for line in file:
        line = line.strip('{}\n')
        array = []
        if line != '':
            array = [int(i) for i in line.split(',')]
        yield arrayToSingleLinkedList(array),
示例#3
0
文件: Parser.py 项目: yanh/pyshua
def parseSingleLinkedListAndTwoInt(file):
    from DataStructure.Utils import arrayToSingleLinkedList
    for line in file:
        listS, twoIntS = line.split('}, ')

        i1, i2 = [int(s) for s in twoIntS.rstrip('\n').split(', ')]

        listS = listS.strip('{}')
        array = []
        if listS != '':
            array = [int(i) for i in listS.split(',')]
        yield arrayToSingleLinkedList(array), i1, i2
示例#4
0
文件: Parser.py 项目: yanh/pyshua
def parseSingleLinkedListAndInt(file):
    from DataStructure.Utils import arrayToSingleLinkedList
    for line in file:
        linkedListString, iString = line.split(', ')

        iString = iString.rstrip('\n')
        i = int(iString)

        linkedListString = linkedListString[1:-1]
        array = []
        if linkedListString != '':
            array = [int(j) for j in linkedListString.split(',')]

        yield arrayToSingleLinkedList(array), i
示例#5
0
文件: Parser.py 项目: yanh/pyshua
def parseSingleLinkedListArray(file):
    from DataStructure.Utils import arrayToSingleLinkedList
    for line in file:
        line = line[1:-2]
        array = []
        if line != '':
            arrayString = line.split('},{')
            for linkedListString in arrayString:
                linkedList = None
                linkedListString = linkedListString.strip('{}')
                if linkedListString != '':
                    linkedList = arrayToSingleLinkedList(
                        [int(i) for i in linkedListString.split(',')]
                    )
                array.append(linkedList)
        yield array,
示例#6
0
文件: Parser.py 项目: yanh/pyshua
def parseCyclicSingleLinkedList(file):
    from DataStructure.Utils import arrayToSingleLinkedList
    for line in file:
        line = line.rstrip('\n')
        listS, cycleS = line.split(', ')

        listS = listS.strip('{}')
        array = []
        if listS != '':
            array = [int(i) for i in listS.split(',')]
        head = arrayToSingleLinkedList(array)

        if cycleS != 'no cycle':
            i = int(cycleS[-1])
            cur = head
            for j in xrange(i):
                cur = cur.next
            ith = cur
            while cur.next:
                cur = cur.next
            tail = cur
            tail.next = ith
        yield head,