def test_isCircularll():
    ll = LinkedListFIFO()
    for i in range(10):
        ll.addNode(i)
    assert (isCircularll(ll) is False)

    lcirc = CicularLinkedListFIFO()
    for i in range(10):
        lcirc.addNode(i)
    assert (isCircularll(lcirc) is True)

    print("테스트 통과!")
def ll_check_palindrome(string):
    str_temp = ''
    for i in string.lower():
        if not i in ' \'"':
            str_temp += i
        else:
            continue

    mid_i = len(str_temp) // 2
    from_fwd_ll = LinkedListFIFO()
    from_back_ll = LinkedListFIFO()

    for i in range(mid_i):
        from_fwd_ll.addNode(str_temp[i])
        from_back_ll.addNode(str_temp[-1 - i])

    fwd_node = from_fwd_ll.head
    back_node = from_back_ll.head
    while fwd_node and back_node:
        if fwd_node.value == back_node.value:
            fwd_node = fwd_node.pointer
            back_node = back_node.pointer
        else:
            return False
    return True
Ejemplo n.º 3
0
def sum_linked_list(ll1, ll2):
    # 연결 리스트: 숫자 2671의 경우 1 7 6 2 순으로 되어있다.
    ll_result = LinkedListFIFO()

    node_1 = ll1.head
    node_2 = ll2.head

    def node_val_or_zero(node):
        if not node is None and node.value:
            return node.value
        else:
            return 0

    def node_pointer_or_None(node):
        if not node is None and node.pointer:
            return node.pointer
        else:
            return None

    pending = 0
    while node_1 or node_2:
        sum_val = node_val_or_zero(node_1) + node_val_or_zero(node_2) + pending
        pending = 0
        if sum_val < 10:
            ll_result.addNode(sum_val)
        else:
            ll_result.addNode(sum_val - 10)
            pending += 1
        node_1 = node_pointer_or_None(node_1)
        node_2 = node_pointer_or_None(node_2)

    return ll_result
Ejemplo n.º 4
0
def test_checkllPal():
    ll = LinkedListFIFO()
    l1 = [1, 2, 3, 2, 1]
    for i in l1:
        ll.addNode(i)
    assert(checkllPal(ll) is True)

    ll.addNode(2)
    ll.addNode(3)
    assert(checkllPal(ll) is False)

    print("테스트 통과!")
def part_linked_list(ll, n):
    result_ll = LinkedListFIFO()
    ll_temp = ll

    node = ll_temp.head
    i = 0
    while node:
        if node.value < n:
            result_ll.addNode(node.value)
            ll_temp.deleteNode(i)
        elif node.value == n:
            ll_temp.deleteNode(i)
        else:
            i += 1
        node = node.pointer

    result_ll.addNode(n)

    node = ll_temp.head
    while node:
        result_ll.addNode(node.value)
        node = node.pointer

    return result_ll
        node = Node(value, self.head)
        if self.tail:
            self.tail.pointer = node
        self.tail = node


def isCircularll(ll):
    p1 = ll.head
    p2 = ll.head

    while p2:
        try:
            p1 = p1.pointer
            p2 = p2.pointer.pointer
        except:
            break

        if p1 == p2:
            return True
    return False


ll = LinkedListFIFO()
for i in range(10):
    ll.addNode(i)
print(isCircularll(ll))

lcirc = CircularLinkedListFIFO()
for i in range(10):
    lcirc.addNode(i)
print(isCircularll(lcirc))
Ejemplo n.º 7
0
def partList(ll, n):
    more = LinkedListFIFO()
    less = LinkedListFIFO()

    node = ll.head

    while node:
        item = node.value

        if item < n:
            less.addNode(item)

        elif item > n:
            more.addNode(item)

        node = node.pointer

    less.addNode(n)
    nodemore = more.head

    while nodemore:
        less.addNode(nodemore.value)
        nodemore = nodemore.pointer

    return less
Ejemplo n.º 8
0
        if item < n:
            less.addNode(item)

        elif item > n:
            more.addNode(item)

        node = node.pointer

    less.addNode(n)
    nodemore = more.head

    while nodemore:
        less.addNode(nodemore.value)
        nodemore = nodemore.pointer

    return less


if __name__ == "__main__":
    ll = LinkedListFIFO()
    l = [6, 7, 3, 4, 9, 5, 1, 2, 8]
    for i in l:
        ll.addNode(i)

    print("분할 전:")
    ll._printList()

    print("분할 후:")
    newll = partList(ll, 6)
    newll._printList()
Ejemplo n.º 9
0
        pending = 0
        if sum_val < 10:
            ll_result.addNode(sum_val)
        else:
            ll_result.addNode(sum_val - 10)
            pending += 1
        node_1 = node_pointer_or_None(node_1)
        node_2 = node_pointer_or_None(node_2)

    return ll_result


list_2671 = [1, 7, 6, 2]
list_355 = [5, 5, 3]

ll_2671 = LinkedListFIFO()
ll_355 = LinkedListFIFO()
for i in list_2671:
    ll_2671.addNode(i)
for i in list_355:
    ll_355.addNode(i)

ll_result = sum_linked_list(ll_2671, ll_355)
ll_result._printList()

###########


class LinkedListFIFOYield(LinkedListFIFO):
    def _printList(self):
        node = self.head
    return result_ll


def part_linked_list_answer_book(ll, n):
    more = LinkedListFIFO()
    less = LinkedListFIFO()

    node = ll.head
    while node:
        item = node.value
        if item < n:
            less.addNode(item)
        elif item > n:
            more.addNode(item)

        node = node.pointer

    less.addNode(n)
    nodemore = mode.head
    while nodemore:
        less.addNode(nodemore.value)
        nodemore = nodemore.pointer
    return less


ll_test = LinkedListFIFO()
for i in [4, 7, 2, 9, 8, 5, 2, 4, 1]:
    ll_test.addNode(i)

part_linked_list(ll_test, 5)._printList()
Ejemplo n.º 11
0
 def _createHashTable(self):
     for i in range(self.size):
         self.slots.append(LinkedListFIFO())