def test(arg_for_seed, length, step):
    seed(arg_for_seed)

    L = [randrange(100) for _ in range(length)]

    LL = ExtendedLinkedList(L)
    LL.print()

    LL.rearrange(step)
    LL.print()
Пример #2
0
def test_base(arg_for_seed, length, L = None):
    if L == None:
        length = (abs(int(length)) + 2) * 2
        seed(arg_for_seed)
        L = [randrange(100) for _ in range(length)]
    else:
        length = len(L)

    LL = ExtendedLinkedList(L)
    LL.print()
    references = collect_references(LL, length)
    LL.rearrange()

    if collect_references(LL, length) != references:
        print('You cheated!')
        sys.exit()
    else:
        LL.print()
Пример #3
0
    references = set()
    for i in range(length):
        references.add(id(node))
        node = node.next_node
    return references


try:
    arg_for_seed, length = input('Enter 2 integers: ').split()
except ValueError:
    print('Incorrect input, giving up.')
    sys.exit()
try:
    # length: an even number at least equal to 4
    arg_for_seed, length = int(arg_for_seed), (abs(int(length)) + 2) * 2
except ValueError:
    print('Incorrect input, giving up.')
    sys.exit()
seed(arg_for_seed)
L = [randrange(100) for _ in range(length)]
#L=[0,1,2,3]
LL = ExtendedLinkedList(L)
LL.print()
references = collect_references(LL, length)
LL.rearrange()
if collect_references(LL, length) != references:
    print('You cheated!')
    sys.exit()
else:
    LL.print()
# Generates a linked list of an even length of 4 or more, determined by user input,
# and reorders the list so that it starts with the first occurrence
# of the smallest element and repeatively moves backwards by one step and forward
# by three steps, wrapping around when needed.

import sys
from random import seed, randrange
from linked_list import *
from extended_linked_list import ExtendedLinkedList

provided_input = input('Enter 2 integers: ')
provided_input = provided_input.split()
if len(provided_input) != 2:
    print('Incorrect input, giving up.')
    sys.exit()
seed(int(provided_input[0]))
# An even number at least equal to 4
length = (abs(int(provided_input[1])) + 2) * 2

L = [0] * length
for i in range(length):
    L[i] = randrange(100)

LL = ExtendedLinkedList(L)
LL.print()
LL.rearrange()
LL.print()
    

Пример #5
0

def collect_references(L, length):
    node = L.head
    references = set()
    for i in range(length):
        references.add(id(node))
        node = node.next_node
    return references


try:
    for_seed, length, upper_bound = [
        int(i) for i in input('Enter three nonnegative integers: ').split()
    ]
    if for_seed < 0 or length < 0 or upper_bound < 0:
        raise ValueError
except ValueError:
    print('Incorrect input, giving up.')
    sys.exit()
seed(for_seed)
LL = ExtendedLinkedList([randrange(upper_bound + 1) for _ in range(length)])
LL.print()
references = collect_references(LL, length)
LL.rearrange()
if collect_references(LL, length) != references:
    print('You cheated!')
    sys.exit()
else:
    LL.print()