コード例 #1
0
from linked_list import LinkedList, Node

linked_list = LinkedList()
node_a = Node(1)
node_b = Node(2)
node_c = Node(3)
node_d = Node(4)
node_e = Node(5)

linked_list.append_node(node_a)
linked_list.append_node(node_b)
linked_list.append_node(node_c)
linked_list.append_node(node_d)
linked_list.append_node(node_e)
node_e.next = node_c


def find_loop_node(linked_list):
    nodes = set()

    current_node = linked_list.head
    while current_node is not None:
        if current_node in nodes:
            return current_node
        else:
            nodes.add(current_node)
            current_node = current_node.next

    return None

コード例 #2
0
from linked_list import LinkedList, Node

node1 = Node(1)

linked_list = LinkedList()
linked_list.append("a")
linked_list.append("b")
linked_list.append("c")
linked_list.append_node(node1)
linked_list.print()

linked_list2 = LinkedList()
linked_list2.append_node(node1)
linked_list2.append("d")
linked_list2.append("e")


def find_intersection(linked_list1, linked_list2):
    if linked_list1.size == 0 or linked_list2.size == 0:
        return None

    current_list = linked_list1
    other_list = linked_list2
    if linked_list1.size < linked_list2.size:
        current_list = linked_list2
        other_list = linked_list1

    set_of_nodes = set()

    current_head = current_list.head
    while current_head is not None:
コード例 #3
0
    print(i)

sweepstakes = Sweepstakes()
sweepstakes.add_contestant("Nate", "Johnson")
sweepstakes.add_contestant("Paige", "Johnson")
sweepstakes.add_contestant("Mason", "Johnson")

sweepstakes.get_winner()

family = Family()
family.add_member("Nate", "Johnson", "Me")
family.add_member("Paige", "Johnson", "Wife")
print(family.members)

linked_list = LinkedList()
linked_list.append_node(5)
linked_list.append_node(30)
linked_list.append_node(65)
linked_list.add_to_beginning(1)
linked_list.add_to_beginning(3)

print(linked_list.contains_node(linked_list.head, 65))
print(linked_list.contains_node(linked_list.head, 64))

new_tree = Binary_Tree(50)
new_tree.add_node(75, new_tree)
new_tree.add_node(25, new_tree)
new_tree.add_node(15, new_tree)
new_tree.add_node(17, new_tree)
new_tree.add_node(80, new_tree)
new_tree.add_node(79, new_tree)