コード例 #1
0
ファイル: 2.4.py プロジェクト: jbaziuk/practice
def add_link_lists(ll1, ll2):
    curr1 = ll1.head
    curr2 = ll2.head
    answer = LinkedList()

    number1 = ""
    number2 = ""

    while curr1 is not None:
        number1 = str(curr1.data) + number1
        curr1 = curr1.next

    while curr2 is not None:
        number2 = str(curr2.data) + number2
        curr2 = curr2.next

    total = str(int(number1) + int(number2))

    for n in total:
        answer.add(int(n))

    return answer
コード例 #2
0
ファイル: 2.2.py プロジェクト: jbaziuk/practice
from GeneralPractice.DataStructurs.LinkedList.SingleUnsortedLinkedList import LinkedList

ll = LinkedList()

ll.add(5)
ll.add(4)
ll.add(3)
ll.add(2)
ll.add(1)

def n_to_last_with_size(ll, n):
    if n > ll.list_size():
        return None
    elif n < 1:
        return None
    cur = ll.head
    count = 1
    while count <=ll.list_size()-n:
        cur = cur.get_next()
        count +=1
    return cur

def n_to_last(ll, n):
    if n < 1:
        return None
    cur = ll.head
    count = 1
    pointer = None
    while cur is not None:
        if count == n:
            pointer = ll.head
コード例 #3
0
ファイル: 2.3.py プロジェクト: jbaziuk/practice
from GeneralPractice.DataStructurs.LinkedList.Node import Node
from GeneralPractice.DataStructurs.LinkedList.SingleUnsortedLinkedList import LinkedList

ll = LinkedList()

ll.add(1)
ll.add(2)
ll.add(3)


def remove_node(n):
    next = n.get_next()
    n.set_data(next.get_data())
    n.set_next(next.get_next())
    return True


node = ll.search_and_return(2)


result = remove_node(node)

temp = 1
コード例 #4
0
ファイル: 2.4.py プロジェクト: jbaziuk/practice
from GeneralPractice.DataStructurs.LinkedList.SingleUnsortedLinkedList import LinkedList

ll1 = LinkedList()

ll1.append(3)
ll1.append(1)
ll1.append(5)

ll2 = LinkedList()
ll2.append(5)
ll2.append(9)
ll2.append(2)


def add_link_lists(ll1, ll2):
    curr1 = ll1.head
    curr2 = ll2.head
    answer = LinkedList()

    number1 = ""
    number2 = ""

    while curr1 is not None:
        number1 = str(curr1.data) + number1
        curr1 = curr1.next

    while curr2 is not None:
        number2 = str(curr2.data) + number2
        curr2 = curr2.next

    total = str(int(number1) + int(number2))
コード例 #5
0
ファイル: 2.5.py プロジェクト: jbaziuk/practice
from GeneralPractice.DataStructurs.LinkedList.SingleUnsortedLinkedList import LinkedList

ll = LinkedList()


ll.add("E")
ll.add("D")
ll.add("C")
ll.add("B")
ll.add("A")
ll.add("A")
ll.add("A")
ll.add("A")



def make_cir():
    E = ll.search_and_return("E")
    C = ll.search_and_return("C")
    E.set_next(C)

def find_start(ll):
    curr = ll.head
    found = False
    o = list()
    while curr is not None and not found:
        if curr in o:
            found = True
            break
        else:
            o.append(curr)