Ejemplo n.º 1
0
def test_middle_k():
    ll = LinkedList()
    ll.append('1')
    ll.append('2')
    ll.append('3')
    ll.append('4')
    ll.append('5')
    ll.append('6')
    assert ll.kth_from_end(3) == '3'
Ejemplo n.º 2
0
def test_insert_before():
    ll = LinkedList()
    ll.append(1)
    ll.append(6)
    ll.append(9)
    ll.insert_before(6, 33)
    assert ll.head.next.value == 33
Ejemplo n.º 3
0
def test_insert_after():
    ll = LinkedList()
    ll.append(1)
    ll.append(6)
    ll.append(9)
    ll.insert_after(9, 11)
    assert ll.head.next.next.next.value == 11
Ejemplo n.º 4
0
def test_kth_from_end_2():
    ll = LinkedList()
    ll.append(1)
    ll.append(3)
    ll.append(8)
    ll.append(2)
    expected = 3
    actual = ll.kth_from_end(2)
    assert expected == actual
Ejemplo n.º 5
0
def test_kth_from_end_same():
    ll = LinkedList()
    ll.append(1)
    ll.append(3)
    ll.append(8)
    ll.append(2)
    expected = "The Value Not Found"
    actual = ll.kth_from_end(4)
    assert expected == actual
Ejemplo n.º 6
0
def test_insert_multipal():
    ll = LinkedList()
    ll.insert(5)
    ll.insert(7)
    ll.insert(8)
    assert ll.head.value == 8
    assert ll.head.next.value == 7
    assert ll.head.next.next.value == 5
    assert ll.head.next.next.next == None
Ejemplo n.º 7
0
def test_append():
    ll = LinkedList()
    ll.append(5)
    ll.append(3)
    ll.append(2)
    assert ll.head.value == 5
    assert ll.head.next.value == 3
    assert ll.head.next.next.value == 2
    assert ll.head.next.next.next == None
Ejemplo n.º 8
0
def zip_lists(list1, list2):
    if not list1:
        return list1
    if not list2:
        return list1
    output = LinkedList()
    current1 = list1.head
    current2 = list2.head
    while current1:
        output.append(current1.value)
        if current2:
            output.append(current2.value)
            current2 = current2.next
        current1 = current1.next
    while current2:
        output.append(current2.value)
        current2 = current2.next
    return output
Ejemplo n.º 9
0
from data_structures_and_algorithms.data_structures.linked_list.linked_list.linked_list import LinkedList


def zip_lists(list1, list2):
    if not list1:
        return list1
    if not list2:
        return list1
    output = LinkedList()
    current1 = list1.head
    current2 = list2.head
    while current1:
        output.append(current1.value)
        if current2:
            output.append(current2.value)
            current2 = current2.next
        current1 = current1.next
    while current2:
        output.append(current2.value)
        current2 = current2.next
    return output


if __name__ == "__main__":
    ll1 = LinkedList()
    ll2 = LinkedList()
Ejemplo n.º 10
0
def test_insert_before_first_node():
    ll = LinkedList()
    ll.append(1)
    ll.insert_before(1, 33)
    assert ll.head.value == 33
Ejemplo n.º 11
0
def test_insert_head():
    ll = LinkedList()
    ll.insert(5)
    assert ll.head.value == 5
Ejemplo n.º 12
0
def test_append_once():
    ll = LinkedList()
    ll.append(1)
    assert ll.head.value == 1
Ejemplo n.º 13
0
def test_empty():
    ll = LinkedList()
    assert ll.head == None
Ejemplo n.º 14
0
def test_string():
    ll = LinkedList()
    ll.insert(9)
    ll.insert(7)
    ll.insert(3)
    assert ll.__str__() == "{ 3 } -> { 7 } -> { 9 } -> NULL"
Ejemplo n.º 15
0
def test_include_false():
    ll = LinkedList()
    ll.insert(4)
    ll.insert(9)
    assert ll.includes(5) == False
Ejemplo n.º 16
0
def test_include_true():
    ll = LinkedList()
    ll.insert(5)
    ll.insert(7)
    assert ll.includes(7) == True
Ejemplo n.º 17
0
def test_zipLists3():
    llist = LinkedList()
    llist1 = LinkedList()
    llist2 = LinkedList()
    llist1.append(3)
    llist1.append(2)
    llist1.append(1)
    llist2.append(8)
    llist2.append(7)
    llist2.append(6)
    llist2.append(5)
    llist2.append(5)
    assert zip_lists(llist1, llist2).__str__(
    ) == "{ 3 } -> { 8 } -> { 2 } -> { 7 } -> { 1 } -> { 6 } -> { 5 } -> { 5 } -> NULL"
Ejemplo n.º 18
0
def test_kth_from_end_size_one():
    ll = LinkedList()
    ll.append(1)
    expected = 1
    actual = ll.kth_from_end(0)
    assert expected == actual
Ejemplo n.º 19
0
def test_insert():
    ll = LinkedList()
    ll.insert(3)
    assert ll.head.value == 3