예제 #1
0
def create_randoms():
    """
    -------------------------------------------------------
    Create a 2D list of Number objects.
    Use: lists = create_randoms()
    -------------------------------------------------------
    Returns:
        lists - TEST lists of SIZE Number objects containing
            values between 0 and XRANGE (list of List of Number)
    -------------------------------------------------------
    """

    lists = List()

    for x in range(TESTS):
        row = []
        for i in range(SIZE):

            v = randint(0, XRANGE)
            num = Number(v)
            row.append(num)

        lists.append(row)

    return lists
예제 #2
0
def create_reversed():
    """
    -------------------------------------------------------
    Create a reversed List of Number objects.
    Use: values = create_reversed()
    -------------------------------------------------------
    Returns:
        values - a reversed list of SIZE Number objects (List of Number)
    -------------------------------------------------------
    """
    values = List()
    for i in range(SIZE - 1, -1, -1):
        temp_num = Number(i)
        values.append(temp_num)

    return values
def create_sorted():
    """
    -------------------------------------------------------
    Creates a sorted List of Number objects.
    Use: values = create_sorted()
    -------------------------------------------------------
    Returns:
        values - a sorted list of SIZE Number objects (List of Number)
    -------------------------------------------------------
    """

    # your code here
    values = List()
    for i in range(SIZE):
        num = Number(i)
        values.append(num)
    return values
예제 #4
0
def create_randoms():
    """
    -------------------------------------------------------
    Create a 2D list of Number objects.
    Use: lists = create_randoms()
    -------------------------------------------------------
    Returns:
        lists - TEST lists of SIZE Number objects containing
            values between 0 and XRANGE (list of List of Number)
    -------------------------------------------------------
    """

    lists = []
    for i in range(TESTS):
        temp = List()
        for j in range(SIZE):
            temp.append(Number(randint(0, XRANGE)))

        lists.append(temp)

    return lists
    def radix_sort(a):
        """
        -------------------------------------------------------
        Performs a base 10 radix sort.
        Use: radix_sort(a)
        -------------------------------------------------------
        Parameters:
            a - a List of base 10 integers (List)
        Returns:
            None
        -------------------------------------------------------
        """
        if len(a) > 0:
            # Determine the maximum digit in the numbers in a.
            max_val = a.max()
            passes = ceil(log(max_val, 10))
            # Create the is_empty buckets.
            buckets = []

            for _ in range(10):
                buckets.append(List())

            for digit in range(passes):
                # Calculate the digit extraction numerator and denominator.
                d = 10**digit
                n = d * 10

                while not a.is_empty():
                    # Move the list nodes to the appropriate bucket.
                    # Extract the individual digit.
                    index = a._front._value % n // d
                    # Move the front node to the proper bucket.
                    buckets[index]._move_front_to_front(a)

                for index in range(len(buckets) - 1, -1, -1):
                    # Move the nodes back to the original list.
                    # (Start with right-most bucket).
                    while not buckets[index].is_empty():
                        a._move_front_to_front(buckets[index])
        return
def create_randoms():
    """
    -------------------------------------------------------
    Create a 2D list of Number objects.
    Use: lists = create_randoms()
    -------------------------------------------------------
    Returns:
        lists - TEST lists of SIZE Number objects containing
            values between 0 and XRANGE (list of List of Number)
    -------------------------------------------------------
    """

    # your code here
    lists = []
    for i in range(TESTS):
        for _ in range(SIZE):
            inner_list = List()
            rand = random.randint(0, XRANGE)
            num = Number(rand)
            inner_list.append(num)
        lists.append(inner_list)
    return lists
예제 #7
0
"""
------------------------------------------------------------------------
Lab 6, Task 5 - Peek and Remove Testing
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-02-25
------------------------------------------------------------------------
"""
from List_linked import List

ll = List()
values = [11,22,33,44,55,66]
for i in values:
    ll.append(i)

val = ll.remove(77)

contents = []
for i in ll:
    contents.append(i)
print("Remove {}, remaining list: {}".format(val, contents))
예제 #8
0
"""
------------------------------------------------------------------------
Lab 7, Task 2 - List#is_identical_r
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-03-04
------------------------------------------------------------------------
"""
from List_linked import List

my_list = List()
other = List()
values = [1, 2, 3, 4]
for val in values:
    my_list.append(val)
for val in values:
    other.append(val)

identical = my_list.is_identical_r(other)

print("List 1 contents: {}".format(values))
print("List 2 contents: {}".format(values))
print("Identical? {}".format(identical))
예제 #9
0
ID:     180856100
Email:  [email protected]
__updated__ = 2019-02-27
------------------------------------------------------------------------
"""
from List_linked import List
from Movie_utilities import read_movies
from Movie import Movie

fh = open('movies.txt', 'r')
movies = read_movies(fh)
# Human readable of movies list
hr_movies = []
for movie in movies:
    hr_movies.append(movie)
my_list = List()

print("Testing 'List#is_identical'")
print("\n\tTest list of movies vs empty list")
my_other_list = List()
for val in hr_movies:
    my_list.append(val)
for val in []:
    my_other_list.append(val)
identical = my_list.is_identical(my_other_list)
print("List 1 Contents: {}".format(hr_movies))
print("List 2 Contents: {}".format([]))
print("Identical? {}\tExpecting: {}".format(identical, False))

print("\n\tTest list of movies vs list of movies")
my_other_list = List()
예제 #10
0
"""
-------------------------------------------------------
[program description]
-------------------------------------------------------
Author:  Max Dann
ID:      190274440
Email:   [email protected]
__updated__ = "2020-03-03"
-------------------------------------------------------
"""
from List_linked import List
l1 = List()
l1.append(1)
l1.append(2)
l1.append(3)
l1.append(4)

even, odd = l1.split_alt_r()
for i in even:
    print(i)
print()
for i in odd:
    print(i)
예제 #11
0
"""
------------------------------------------------------------------------
Lab 7, Task 3 - List#split_alt_r
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-03-04
------------------------------------------------------------------------
"""
from List_linked import List

my_list = List()
values = [11, 22, 33, 44, 55, 66]
for val in values:
    my_list.append(val)
even, odd = my_list.split_alt_r()

e_contents = []
for node in even:
    e_contents.append(node)
o_contents = []
for node in odd:
    o_contents.append(node)

print("Even: {}".format(e_contents))
print("Odd: {}".format(o_contents))

my_list = List()
values = [99]
for val in values:
예제 #12
0
Email:  [email protected]
__updated__ = 2019-03-06
------------------------------------------------------------------------
"""
from List_linked import List
from Movie_utilities import read_movies
from Movie import Movie

fh = open('movies.txt', 'r')
movies = read_movies(fh)
movies_mid = len(movies) // 2


print("\n\nTesting List#is_identical")
print("\nSame values")
my_list = List()
other_list = List()
for val in movies:
    my_list.append(val)
    other_list.append(val)
    
identical = my_list.is_identical(other_list)

print("List 1 contents: {}".format([val for val in my_list]))
print("List 2 contents: {}".format([val for val in other_list]))
print("Identical? {}\tExpected: {}".format(identical, True))

print("\nDifferent values")
my_list = List()
other_list = List()
for val in movies[:movies_mid]:
예제 #13
0
"""
-------------------------------------------------------------
[T01]
-------------------------------------------------------------
Author:  Anshul Khatri
ID:      193313680
Email:   [email protected]
Section: CP164 Winter 2020
__updated__ = "2020-03-05"
-------------------------------------------------------------
"""
from Food import Food
from Food_utilities import read_foods
from List_linked import List

l1 = List()
l2 = List()

print("Identical:", l1.is_identical(l2))
print("----------")
print()

fv = open("food.txt", 'r')
foods = read_foods(fv)
fv2 = open("food2.txt", 'r')
foods2 = read_foods(fv2)

for a in range(len(foods)):
    l1.insert(a, foods[a])
for a in range(len(foods2)):
    l2.insert(a, foods2[a])
예제 #14
0
파일: t02.py 프로젝트: maxkdann/CP164
"""
-------------------------------------------------------
[program description]
-------------------------------------------------------
Author:  Max Dann
ID:      190274440
Email:   [email protected]
__updated__ = "2020-03-03"
-------------------------------------------------------
"""
from List_linked import List
l1 = List()
l2 = List()
l1.append(1)
l2.append(1)
print(l1.is_identical_r(l2))