Exemple #1
0
    node2 = Node(1)
    node3 = Node(6)

    node4 = Node(5)
    node5 = Node(9)
    node6 = Node(2)
    node7 = Node(1)

    node1.next = node2
    node2.next = node3

    node4.next = node5
    node5.next = node6
    node6.next = node7
    # Creating 1st Linkedlist
    l1 = LinkedList(node1)
    # Creating 2nd Linkedlist
    l2 = LinkedList(node4)

    print("Digits store in reverse order")
    l1.printElements()
    print('+')
    l2.printElements()
    sumNode = sumList(l1.head, l2.head, 0)
    ll = LinkedList(sumNode)
    print('=')
    ll.printElements()

    print("\nDigits store in forward order")
    l1.printElements()
    print('+')
Exemple #2
0
    node7 = Node("17")
    node8 = Node("23")
    node9 = Node("825")
    node10 = Node("27")

    node11 = Node("3")
    node12 = Node("5")

    node1.next = node2
    node2.next = node3
    node3.next = node4
    node4.next = node5
    node5.next = node6
    node6.next = node7
    node7.next = node8
    node8.next = node9
    node9.next = node10

    node11.next = node12
    node12.next = node6
    # Creating Linkedlist
    l1 = LinkedList(node1)
    l1.printElements()

    l2 = LinkedList(node11)
    print('\n')
    l2.printElements()

    node = findIntersection(l1.head, l2.head)
    print('\n' + node.data)
Exemple #3
0

if __name__ == "__main__":
    # Creating nodes
    node1 = Node(3)
    node2 = Node(5)
    node3 = Node(89)
    node4 = Node(17)
    node5 = Node(13)
    node6 = Node(215)
    node7 = Node(17)
    node8 = Node(23)
    node9 = Node(825)
    node10 = Node(27)
    node1.next = node2
    node2.next = node3
    node3.next = node4
    node4.next = node5
    node5.next = node6
    node6.next = node7
    node7.next = node8
    node8.next = node9
    node9.next = node10
    # Creating Linkedlist
    ll = LinkedList(node1)
    ll.printElements()

    partition(ll, 23)
    print("##")
    ll.printElements()
Exemple #4
0
if __name__ == "__main__":
    # Creating nodes
    node1 = Node("3")
    node2 = Node("5")
    node3 = Node("89")
    node4 = Node("17")
    node5 = Node("13")
    node6 = Node("215")
    node7 = Node("17")
    node8 = Node("23")
    node9 = Node("825")
    node10 = Node("27")
    node11 = Node("7")
    node1.next = node2
    node2.next = node3
    node3.next = node4
    node4.next = node5
    node5.next = node6
    node6.next = node7
    node7.next = node8
    node8.next = node9
    node9.next = node10
    node10.next = node11
    node11.next = node4

    # Creating Linkedlist
    ll = LinkedList(node1)
    node = detectLoop(ll.head)
    print(node.data)