Exemplo n.º 1
0
def main():
    L = arraylist.arrayList()
    for i in range(0, 3):
        Q = arraylist.arrayList()
        for j in range(0, 5):
            Q.INSERT((i + 1) * j, j)
        L.INSERT(Q, i)

    print "Internal lists:"
    print L.arr[0].arr, L.arr[1].arr, L.arr[2].arr

    result = concat.concat(L)
    expected = [0, 1, 2, 3, 4, 0, 2, 4, 6, 8, 0, 3, 6, 9, 12]

    print "Result list:"
    print result.arr

    print "Expected list:"
    print expected

    if result.arr == expected:
        passed = True
    else:
        passed = False

    testPass("concat", passed)
Exemplo n.º 2
0
def main():
	L = arraylist.arrayList()
	for i in range(0,3):
		Q = arraylist.arrayList()
		for j in range(0,5):
			Q.INSERT((i+1)*j,j)
		L.INSERT(Q,i)

	print "Internal lists:"
	print L.arr[0].arr, L.arr[1].arr, L.arr[2].arr

	result = concat.concat(L)
	expected = [0,1,2,3,4,0,2,4,6,8,0,3,6,9,12]

	print "Result list:"
	print result.arr
	
	print "Expected list:"
	print expected

	if result.arr == expected:
		passed = True
	else:
		passed = False

	testPass("concat",passed)
Exemplo n.º 3
0
def main():
	a = arraylist.arrayList()
	b = arraylist.arrayList()
	c = arraylist.arrayList()
	for i in range(0,5):
		a.INSERT(i+1,i)
	for i in range(0,7):
		b.INSERT(i+2,i)
	for i in range(0,3):
		c.INSERT(i-2,i)

	print "3 Lists to merge:"
	print "A: ", a.arr
	print "B: ", b.arr
	print "C: ", c.arr

	result = listmerge.merge(a,b,c)
	expected = [-2, -1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8]

	print "Result List:"
	print result.arr

	print "Expected List:"
	print expected

	if result.arr == expected:
		passed = True
	else:
		passed = False

	testPass("listmerge",passed)
Exemplo n.º 4
0
def concat(L):
    M = arraylist.arrayList()
    count = 0
    for p in range(0, L.END()):
        for q in range(0, L.arr[p].END()):
            M.INSERT(L.arr[p].arr[q], count)
            count = count + 1
    return M
Exemplo n.º 5
0
def concat(L):
	M = arraylist.arrayList()
	count = 0
	for p in range (0,L.END()):
		for q in range (0,L.arr[p].END()):
			M.INSERT(L.arr[p].arr[q], count)
			count= count + 1
	return M
Exemplo n.º 6
0
def main():
    x = arraylist.arrayList()
    y = pointerlist.pointerList()

    print "Testing arraylist:"
    genTest(x)

    print "\n", "Testing pointerlist:"
    genTest(y)
Exemplo n.º 7
0
def merge(*L):
	M = arraylist.arrayList()
	count = 0
	for p in range(0,len(L)):	
		for q in range (0,L[p].END()):
			M.INSERT(L[p].arr[q], count)
			count = count + 1
	M.arr = sorted(M.arr)
	return M
Exemplo n.º 8
0
def merge(*L):
    M = arraylist.arrayList()
    count = 0
    for p in range(0, len(L)):
        for q in range(0, L[p].END()):
            M.INSERT(L[p].arr[q], count)
            count = count + 1
    M.arr = sorted(M.arr)
    return M
Exemplo n.º 9
0
def mergelists(*lists):
    # Compile all lists supplied into a composite list
    c_index = 0
    composite_list = arrayList([])
    for list in lists:
        c_index = c_index + 1
        composite_list.INSERT(list, c_index)
    # Add composite list elements in a sorted fashion
    m_index = 1
    merged_list = listconcat(composite_list)
    final_length = merged_list.END() - merged_list.FIRST()
    merged_sorted_list = arrayList([])
    while (merged_sorted_list.END() - merged_sorted_list.FIRST() != final_length):
        current_min_index = 1
        current_min = merged_list.RETRIEVE(current_min_index)
        for index in range(merged_list.FIRST(), merged_list.END()):
            element = merged_list.RETRIEVE(index)
            if element < current_min:
                current_min = element
                current_min_index = index
        merged_sorted_list.INSERT(current_min, m_index)
        m_index = m_index + 1
        merged_list.DELETE(current_min_index)
    return merged_sorted_list
Exemplo n.º 10
0
def listconcat(list_of_lists):
    # Start with a Null list
    concatenated_list = arrayList([])
    index = 1
    outer_first = list_of_lists.FIRST()
    outer_last = list_of_lists.END()
    # Step through each element in the list of lists
    for outer_element_index in range(outer_first, outer_last):
        outer_element = list_of_lists.RETRIEVE(outer_element_index)
        inner_first = outer_element.FIRST()
        inner_last = outer_element.END()
        # Step through each element of each list in the list of lists
        for inner_element_index in range(inner_first, inner_last):
            # Retrieve that element and insert it into the concatenated list
            inner_element = outer_element.RETRIEVE(inner_element_index)
            concatenated_list.INSERT(inner_element, index)
            index = index + 1
    return concatenated_list
Exemplo n.º 11
0
        inner_first = outer_element.FIRST()
        inner_last = outer_element.END()
        # Step through each element of each list in the list of lists
        for inner_element_index in range(inner_first, inner_last):
            # Retrieve that element and insert it into the concatenated list
            inner_element = outer_element.RETRIEVE(inner_element_index)
            concatenated_list.INSERT(inner_element, index)
            index = index + 1
    return concatenated_list


if __name__ == '__main__':
    print(
        "Let's fill our test list up with four lists \n[[A, B], [C], [D, E, F, G], [H, I]]"
    )
    test_list = arrayList()
    list_1 = arrayList(["A", "B"])
    list_2 = arrayList(["C"])
    list_3 = arrayList(["D", "E", "F", "G"])
    list_4 = arrayList(["H", "I"])
    test_list.INSERT(list_1, 1)
    test_list.INSERT(list_2, 2)
    test_list.INSERT(list_3, 3)
    test_list.INSERT(list_4, 4)
    print("Testing for list structure validity...")
    assert (test_list.RETRIEVE(1) == list_1)
    assert (test_list.RETRIEVE(2) == list_2)
    assert (test_list.RETRIEVE(3) == list_3)
    assert (test_list.RETRIEVE(4) == list_4)
    print("Structure validity confirmed!")
    print("Concatenating the list of lists...")
Exemplo n.º 12
0
def main():

	t = []
	u = []
	v = []
	ta = []
	ua = []
	va = []

	x = arraylist.arrayList()
	y = arraylist.arrayList()
	z = arraylist.arrayList()
	xa = arraylist.arrayList()
	ya = arraylist.arrayList()
	za = arraylist.arrayList()
	
	a = pointerlist.pointerList()
	b = pointerlist.pointerList()
	c = pointerlist.pointerList()
	aa = pointerlist.pointerList()
	ba = pointerlist.pointerList()
	ca = pointerlist.pointerList()

	pyA = pyins(t,2000,"front")
	pyB = pyins(u,4000,"front")
	pyC = pyins(v,8000,"front")

	arrA = instime(x,2000,"front")
	arrB = instime(y,4000,"front")
	arrC = instime(z,8000,"front")

	pointA = instime(a,2000,"front")
	pointB = instime(b,4000,"front")
	pointC = instime(c,8000,"front")

	print "=============INSERT(Front)=========="
	print "|SIZE|DATSTRUCT|__ARRAY__|_POINTER_|"
	print "|2000|",format(pyA,'.5f'),"|",format(arrA,'.5f'),"|",format(pointA,'.5f'),"|"
	print "|4000|",format(pyB,'.5f'),"|",format(arrB,'.5f'),"|",format(pointB,'.5f'),"|"
	print "|8000|",format(pyC,'.5f'),"|",format(arrC,'.5f'),"|",format(pointC,'.5f'),"|"
	print "===================================="

	pyA = pyins(ta,2000,"back")
	pyB = pyins(ua,4000,"back")
	pyC = pyins(va,8000,"back")

	arrA = instime(xa,2000,"back")
	arrB = instime(ya,4000,"back")
	arrC = instime(za,8000,"back")

	pointA = instime(aa,2000,"back")
	pointB = instime(ba,4000,"back")
	pointC = instime(ca,8000,"back")

	print "=============INSERT(Back)==========="
	print "|SIZE|DATSTRUCT|__ARRAY__|_POINTER_|"
	print "|2000|",format(pyA,'.5f'),"|",format(arrA,'.5f'),"|",format(pointA,'.5f'),"|"
	print "|4000|",format(pyB,'.5f'),"|",format(arrB,'.5f'),"|",format(pointB,'.5f'),"|"
	print "|8000|",format(pyC,'.5f'),"|",format(arrC,'.5f'),"|",format(pointC,'.5f'),"|"
	print "===================================="


	pyA = pyret(t,2000)
	pyB = pyret(u,4000)
	pyC = pyret(v,8000)
	
	arrA = rettime(x,2000)
	arrB = rettime(y,4000)
	arrC = rettime(z,8000)

	pointA = rettime(a,2000)
	pointB = rettime(b,4000)
	pointC = rettime(c,8000)

	print "============RETRIEVE================"
	print "|SIZE|DATSTRUCT|__ARRAY__|_POINTER_|"
	print "|2000|",format(pyA,'.5f'),"|",format(arrA,'.5f'),"|",format(pointA,'.5f'),"|"
	print "|4000|",format(pyB,'.5f'),"|",format(arrB,'.5f'),"|",format(pointB,'.5f'),"|"
	print "|8000|",format(pyC,'.5f'),"|",format(arrC,'.5f'),"|",format(pointC,'.5f'),"|"
	print "===================================="


	pyA = pydel(t,2000,"front")
	pyB = pydel(u,4000,"front")
	pyC = pydel(v,8000,"front")

	arrA = deltime(x,2000,"front")
	arrB = deltime(y,4000,"front")
	arrC = deltime(z,8000,"front")

	pointA = deltime(a,2000,"front")
	pointB = deltime(b,4000,"front")
	pointC = deltime(c,8000,"front")

	print "=============DELETE(Front)=========="
	print "|SIZE|DATSTRUCT|__ARRAY__|_POINTER_|"
	print "|2000|",format(pyA,'.5f'),"|",format(arrA,'.5f'),"|",format(pointA,'.5f'),"|"
	print "|4000|",format(pyB,'.5f'),"|",format(arrB,'.5f'),"|",format(pointB,'.5f'),"|"
	print "|8000|",format(pyC,'.5f'),"|",format(arrC,'.5f'),"|",format(pointC,'.5f'),"|"
	print "===================================="


	pyA = pydel(ta,2000,"front")
	pyB = pydel(ua,4000,"front")
	pyC = pydel(va,8000,"front")

	arrA = deltime(xa,2000,"front")
	arrB = deltime(ya,4000,"front")
	arrC = deltime(za,8000,"front")

	pointA = deltime(aa,2000,"front")
	pointB = deltime(ba,4000,"front")
	pointC = deltime(ca,8000,"front")

	print "=============DELETE(Back)==========="
	print "|SIZE|DATSTRUCT|__ARRAY__|_POINTER_|"
	print "|2000|",format(pyA,'.5f'),"|",format(arrA,'.5f'),"|",format(pointA,'.5f'),"|"
	print "|4000|",format(pyB,'.5f'),"|",format(arrB,'.5f'),"|",format(pointB,'.5f'),"|"
	print "|8000|",format(pyC,'.5f'),"|",format(arrC,'.5f'),"|",format(pointC,'.5f'),"|"
	print "===================================="
Exemplo n.º 13
0
        current_min = merged_list.RETRIEVE(current_min_index)
        for index in range(merged_list.FIRST(), merged_list.END()):
            element = merged_list.RETRIEVE(index)
            if element < current_min:
                current_min = element
                current_min_index = index
        merged_sorted_list.INSERT(current_min, m_index)
        m_index = m_index + 1
        merged_list.DELETE(current_min_index)
    return merged_sorted_list


if __name__ == '__main__':
    print("Let's start off initializing a few lists.")
    print("[A, D, E]")
    list_1 = arrayList(["A", "D", "E"])
    print("[B, F, I]")
    list_2 = arrayList(["B", "F", "I"])
    print("[C, K, L]")
    list_3 = arrayList(["C", "K", "L"])
    print("[G, H, J, M, N, O]")
    list_4 = arrayList(["G", "H", "J", "M", "N", "O"])
    print("Merging all sorted lists...")
    test_m_list = mergelists(list_1, list_2, list_3, list_4)
    print("Lists merged!")
    print("Confirming sorted structure of merged list...")
    py_sortable_list = []
    for i in range(1, test_m_list.END()):
        py_sortable_list.append(test_m_list.RETRIEVE(i))
    sorted_list = py_sortable_list.copy()
    sorted_list.sort()