Ejemplo n.º 1
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
Ejemplo n.º 2
0
from random import randint


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)
Ejemplo n.º 3
0
from random import randint, getrandbits
from singly_list import SinglyList

def yard(alice, bob):
	cars = sorted([car for car in alice] + [car for car in bob])
	return cars

if __name__ == '__main__':
	alice = []
	bob = []
	for x in range(randint(10, 15)):
		who = alice if getrandbits(1) else bob
		who.append(randint(1,20))
	print("Alice:", alice, sep=' ')
	print("Bob:", bob, sep=' ')
	carol = SinglyList()
	dave = SinglyList()
	[carol.add_tail(carol.h, x) for x in alice + bob]
	carol.sort()
	while carol.size() > 2:
		dave.add_tail(dave.h, carol.h)
		carol.remove(carol.h, carol.h)
	print("Carol:", carol, sep=' ')
	print("Dave:", dave, sep=' ')