from linked_list import LinkedList from detect_cycle import detect_cycle def find_pos(head, node): pos = -1 temp = head if node == None: return pos while temp != node: pos = pos + 1 temp = temp.next return pos+1 def find_length(head): length = 0 temp = head while temp != None: length = length + 1 temp = temp.next return length def find_tail(head): temp = head for i in range(find_length(head) - 1): temp = temp.next return temp def main(input_1,input_2): linked_list = LinkedList() linked_list.create_linked_list(input_1) if input_2 != -1: temp = linked_list.head for i in range(input_2): temp = temp.next tail = find_tail(linked_list.head) tail.next = temp return detect_cycle(linked_list.head)