def main():
    ll = LinkList()
    l1 = [1, 2, 3, 2, 1]
    for i in l1:
        ll.addNode(i)
    print(checkllPal(ll))
 
    ll.addNode(2)
    ll.addNode(3)
    print(checkllPal(ll))
def main():
    ll = LinkList()
    l1 = [6, 7, 3, 4, 9, 5, 1, 2, 8]
    for i in l1:
        ll.addNode(i)
    print('Before Part')
    ll.printList()
    print('After Part')
    newll = partList(ll, 6)
    newll.printList()
def main():
    ll = LinkList()
    l1 = [6, 7, 3, 4, 9, 5, 1, 2, 8]
    for i in l1:
        ll.addNode(i)
    print('Before Part')    
    ll.printList()
    print('After Part')
    newll = partList(ll, 6)
    newll.printList()
Exemplo n.º 4
0
def main():
    ll = CircLinkList()
    for i in range(10):
        ll.addNode(i)
    ll.printList()
    
    print(isCircularll(ll))
    
    ll2 = LinkList()
    for i in range(10):
        ll2.addNode(i)
    ll2.printList() 

    print(isCircularll(ll2)) 
def main():
    l1 = LinkList() # 2671
    l1.addNode(1)
    l1.addNode(7)
    l1.addNode(6)
    l1.addNode(2)
    
    l2 = LinkList() # 455
    l2.addNode(5)
    l2.addNode(5)
    l2.addNode(4)
    
    lsum = sumlls(l1, l2)
    lsum.printList()# 3126
def main():
    l1 = LinkList()  # 2671
    l1.addNode(1)
    l1.addNode(7)
    l1.addNode(6)
    l1.addNode(2)

    l2 = LinkList()  # 455
    l2.addNode(5)
    l2.addNode(5)
    l2.addNode(4)

    lsum = sumlls(l1, l2)
    lsum.printList()  # 3126
def partList(ll, n):
    more = LinkList()
    less = LinkList()
    node_old = ll.head
    while node_old:
        item = node_old.value
        if item < n:
            less.addNode(item)
        elif item > n:
            more.addNode(item)
        node_old = node_old.next

    less.addNode(n)
    nodemore = more.head
    while nodemore:
        less.addNode(nodemore.value)
        nodemore = nodemore.next
    return less
def partList(ll, n):
    more = LinkList()
    less = LinkList()
    node_old = ll.head
    while node_old:
        item = node_old.value
        if item < n:
            less.addNode(item)
        elif item > n:
            more.addNode(item)
        node_old = node_old.next
    
    less.addNode(n)
    nodemore = more.head
    while nodemore:
        less.addNode(nodemore.value)
        nodemore = nodemore.next  
    return less
def sumlls(l1, l2):
    lsum = LinkList()
    dig1 = l1.head
    dig2 = l2.head
    next = 0
    while dig1 and dig2:
        d1 = dig1.value
        d2 = dig2.value      
        sum_d = d1 + d2 + next
        if sum_d > 9:
            next = sum_d//10
            lsum.addNode(sum_d%10)
            
        else:   
            lsum.addNode(sum_d)
            next = 0
        
        dig1 = dig1.next
        dig2 = dig2.next
    
    if dig1:
        sum_d = next + dig1.value
        if sum_d > 9:
            lsum.addNode(sum_d%10)           
        else:   
            lsum.addNode(sum_d)   
        dig1 = dig1.next
    
    if dig2:
        sum_d = next + dig2.value
        if sum_d > 9:
            lsum.addNode(sum_d%10)           
        else:   
            lsum.addNode(sum_d)   
        dig2 = dig2.next    
    
    
    return lsum
def sumlls(l1, l2):
    lsum = LinkList()
    dig1 = l1.head
    dig2 = l2.head
    next = 0
    while dig1 and dig2:
        d1 = dig1.value
        d2 = dig2.value
        sum_d = d1 + d2 + next
        if sum_d > 9:
            next = sum_d // 10
            lsum.addNode(sum_d % 10)

        else:
            lsum.addNode(sum_d)
            next = 0

        dig1 = dig1.next
        dig2 = dig2.next

    if dig1:
        sum_d = next + dig1.value
        if sum_d > 9:
            lsum.addNode(sum_d % 10)
        else:
            lsum.addNode(sum_d)
        dig1 = dig1.next

    if dig2:
        sum_d = next + dig2.value
        if sum_d > 9:
            lsum.addNode(sum_d % 10)
        else:
            lsum.addNode(sum_d)
        dig2 = dig2.next

    return lsum