Example #1
0
def create_level_linked_list(tree, node_lists, level):
    if tree is None:
        return
    node_list = None

    if len(node_lists) == level:
        node_list = LinkedList()
        node_lists.append(node_list)
    else:
        node_list = node_lists[level]

    if node_list.head is None:
        node_list.head = LinkedNode(tree.value)
    else:
        node_list.head.append_to_tail(tree.value)

    create_level_linked_list(tree.left, node_lists, level + 1)
    create_level_linked_list(tree.right, node_lists, level + 1)
Example #2
0
            else:
                before_end.next = n
                before_end = n
        else:
            if after_start is None:
                after_start = n
                after_end = after_start
            else:
                after_end.next = n
                after_end = n
        n = next

    if before_start is None:
        return

    before_end.next = after_start


if __name__ == "__main__":
    linked_list = LinkedList()
    linked_list.head = LinkedNode(3)
    linked_list.head.append_to_tail(5)
    linked_list.head.append_to_tail(8)
    linked_list.head.append_to_tail(5)
    linked_list.head.append_to_tail(10)
    linked_list.head.append_to_tail(2)
    linked_list.head.append_to_tail(1)
    linked_list.list_print()
    partition(linked_list.head, 5)
    linked_list.list_print()