コード例 #1
0
ファイル: tests.py プロジェクト: ingniq/algorithms
    def __init__(self, *args, **kwargs):
        n1 = Node(12)
        n2 = Node(55)
        n3 = Node(12)
        n1.next = n2
        n2.next = n3

        self.linked_list = LinkedList()
        self.linked_list.head = n1
        self.linked_list.tail = n3

        super(TestLinkedListMethods, self).__init__(*args, **kwargs)
コード例 #2
0
def main():

	node = Node(5)
	head = node
	node.next = Node(3)
	node.next.next = None
	temp = Node(5)
	head2 = temp
	temp.next = Node(8)

	print(temp.data)
	print(node.data)
	node.data = 3
	print(temp.data)
	print(node.data)
コード例 #3
0
def main():

    node2 = Node(2)
    node2.next = Node(5)
    node2.next.next = Node(7)
    node2.next.next.next = Node(8)
    node2.next.next.next.next = Node(9)
    node1 = Node(2)
    node1.next = Node(1)
    node1.next.next = Node(8)
    node1.next.next.next = Node(6)
    node1.next.next.next.next = node2.next.next
    node3 = ll_intersection(node1, node2)
    if not node3:
        print(node3)
    else:
        while node3:
            print(node3.data)
            node3 = node3.next
コード例 #4
0
def main():
    node = Node("A")
    node.next = Node("B")
    node.next.next = Node("C")
    node.next.next.next = Node("D")
    node.next.next.next.next = Node("E")
    node.next.next.next.next.next = Node("F")
    node.next.next.next.next.next.next = Node("G")
    node.next.next.next.next.next.next.next = node.next.next.next
    node2 = loop_detection(node)
    print(node2.data)
コード例 #5
0
ファイル: q2_5.py プロジェクト: keithxm23/CTCI
#sum two numbers given as linked lists

from ll import Node
import copy

num1 = raw_input("Enter the first number: ")
num2 = raw_input("Enter the second number: ")


numA = None
for x in num1:
	temp = Node(int(x))
	temp.next = numA
	numA = temp

numB = None
for x in num2:
	temp = Node(int(x))
	temp.next = numB
	numB = temp

carry = 0
sum = None
curA = numA
curB = numB

while(curA != None or curB != None):
	if curA == None:
		Aval = 0
		Bval = curB.data
		curB = curB.next
コード例 #6
0
 def push(self, data):
     n = Node(data)
     n.next = self.head
     self.head = n
     return self.head