Exemplo n.º 1
0
def solution():
    print "2-2 return k-th to last, pls enter linked list value with space to split."
    raw_values = raw_input("values >> ")
    values = [float(i) for i in raw_values.strip().split()]
    k = int(raw_input("k >> "))
    l1 = LinkedList(values)
    l1.tranverse()
    KthToLast_recu(l1.head, k)
Exemplo n.º 2
0
def solution():
    print "2-1 Remove dups. Pls enter linked list values, split by single space."
    raw_values = raw_input("values >> ")
    values = [float(val) for val in raw_values.strip().split()]
    l1 = LinkedList(values)
    l1.tranverse()
    removeDups(l1.head)
    l1.tranverse()
Exemplo n.º 3
0
def solution():
    print "2-5 sum lists."
    l1 = LinkedList([8,6,4,2])
    l2 = LinkedList([4,5,7,9,2,4,6,8])
    l1.tranverse()
    l2.tranverse()
    l3 = sumLists(l1.head, l2.head)
    l3.tranverse()
Exemplo n.º 4
0
def solution():
    print "2-4 Partition."
    raw_values = raw_input("values >> ")
    if raw_values.strip() == "":
        values = [3,5,8,5,10,2,1]
    else:
        values = [float(i) for i in raw_values.strip().split()]
    l1 = LinkedList(values)
    l1.tranverse()
    val = float(raw_input("select a value >> "))
    partition(l1.head, val)
    l1.tranverse()
Exemplo n.º 5
0
def solution():
    print "2-3 delete middle node, pls enter linked list values. Enter for default"
    raw_values = raw_input("values >> ")
    if raw_values.strip() == "":
        values = [1,2,3,4,5,6,7,8,9,10]
    else:
        values = [float(i) for i in raw_values.strip().split()]
    l1 = LinkedList(values)
    l1.tranverse()
    print "Please enter 1 < c < 10 as the middle node number:"
    c = int(raw_input("c >> "))
    c_node = l1.returnKthNode(c)
    deleteMiddleNode(c_node)
    l1.tranverse()