示例#1
0
def main():
    trainWon = SinglyList()
    trainToo = SinglyList()

    for i in range(10):
        trainWon.add_head(Node(random.randint(1, 100)))

    for i in range(10):
        trainToo.add_head(Node(random.randint(1, 100)))
    '''
    #00 Test
    PrintList.print_list(disList.head)
    disList.add_head(Node("lmao"))
    PrintList.print_list(None)
    PrintList.print_list(disList.head)

    #01 Test
    PrintList.print_list(disList.head)
    PrintList.add_tail(disList.head, 10)
    PrintList.print_list(disList.head)

    #02 Test
    SinglyList.print_list(disList.head)
    disList.remove(disList.head, 4)
    SinglyList.print_list(disList.head)

    #03 Test
    print(SinglyList.has_cycle(disList.head))

    #04 Test
    SinglyList.print_list(trainWon.head)
    SinglyList.print_list(trainToo.head)
    SinglyList.print_list(SinglyList.merge(trainWon.head, trainToo.head))

    #05 Test
    SinglyList.print_list(disList.head)
    disList.sort_dsc(disList.head)
    SinglyList.print_list(disList.head)
    '''
    #06 "Test"
    SinglyList.print_list(trainWon.head)
    SinglyList.print_list(trainToo.head)
    trainWon.sort_dsc(trainWon.head)
    trainToo.sort_dsc(trainToo.head)
    SinglyList.print_list(SinglyList.merge(trainWon.head, trainToo.head))
示例#2
0
from singly_list import SinglyList
from node import Node

disList = SinglyList()

disList.add_head(Node(4))
for i in range(1,10):
    disList.add_head(Node(i))

disList.add_head(Node(4))
disList.add_head(Node(5))
disList.add_head(Node(8))
disList.add_head(Node(4))
'''
#00 Test
PrintList.print_list(disList.head)
disList.add_head(Node("lmao"))
PrintList.print_list(None)
PrintList.print_list(disList.head)

#01 Test
PrintList.print_list(disList.head)
PrintList.add_tail(disList.head, 10)
PrintList.print_list(disList.head)
'''
#02 Test
SinglyList.print_list(disList.head)
disList.remove(disList.head, 4)
SinglyList.print_list(disList.head)
示例#3
0
def train(size, parity):
    out = SinglyList()
    if parity == 0:
        size = 2 * int(size / 2)
    elif size % 2 == 0:
        size -= 1
    for x in range(size, 0, -2):
        out.add_tail(out.head, x)
    return out


list_a = SinglyList()
[list_a.add_tail(list_a.head, x) for x in range(8, 3, -1)]
list_a.remove(list_a.head, 6)
list_a.print_list(list_a.head)
print('Cycle? ', end='')
print('yes' if list_a.has_cycle(list_a.head) else 'no')
tail = list_a.head
while tail.next:
    tail = tail.next
tail.next = list_a.head
print('Cycle? ', end='')
print('yes' if list_a.has_cycle(list_a.head) else 'no')
tail.next = None
list_a = train(10, 0)
list_b = train(10, 1)
print('Merge:')
train = SinglyList.merge(list_a.head, list_b.head)
list_a.print_list(train)
list_c = SinglyList()
示例#4
0
for i in range(1, 10):
    if random.random() > 0.9:
        trainWon.add_head(Node(i))
    else:
        trainToo.add_head(Node(i))
'''
#00 Test
PrintList.print_list(disList.head)
disList.add_head(Node("lmao"))
PrintList.print_list(None)
PrintList.print_list(disList.head)

#01 Test
PrintList.print_list(disList.head)
PrintList.add_tail(disList.head, 10)
PrintList.print_list(disList.head)

#02 Test
SinglyList.print_list(disList.head)
disList.remove(disList.head, 4)
SinglyList.print_list(disList.head)

#03 Test
print(SinglyList.has_cycle(disList.head))
'''
#04 Test
SinglyList.print_list(trainWon.head)
SinglyList.print_list(trainToo.head)
SinglyList.print_list(SinglyList.merge(trainWon.head, trainToo.head))