Exemple #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))
Exemple #2
0
    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()
[list_c.add_tail(list_c.head, randint(1, 20)) for x in range(randint(7, 13))]
list_c.sort()
print("Random sorted list:")
list_c.print_list(list_c.h)
Exemple #3
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))