def main(argv=None): chain1 = chaintable.ChainTable() for i in range(7): chain1.append(i) L = FindKthToTail(chain1, 2) data = L._repr_() print(data)
import chaintable def print_chain(temp): # given the head of chain ,then print the whole chain string = '' while not temp == None: string += str(temp.data) + ' ' temp = temp._next print(string) a = chaintable.ChainTable() for i in range(6): a.append(i) print(a) def removeNthFromEnd(head, n): if head._next == None: return None pre = head cur = head for i in range(n): cur = cur._next if cur == None: return head._next while not cur._next == None: cur = cur._next pre.pre._next pre._next = pre._next._next
import chaintable,random def print_chain(temp): # given the head of chain ,then print the whole chain string = '' while not temp == None: string += str(temp.data) + ' ' temp = temp._next print(string) a=chaintable.ChainTable() b=chaintable.ChainTable() random1=[] random2=[] for i in range(random.randint(5,20)): random1.append(random.randint(1,50)) random1.sort() for i in range(random.randint(5,15)): random2.append(random.randint(1,50)) random2.sort() for k in random1: a.append(k) for k in random2: b.append(k) print(a)