Implement a class QuickList
with the following methods:
move(k)
: move the firstk
elements of the list to the end of the listget(i)
: return the element at the index
The initial contents of the list is given as a parameter to the constructor. The time complexity of both methods should be .
In a file quicklist.py
, implement a class QuickList
according to the following template:
class QuickList: def __init__(self, t): # TODO def move(self, k): # TODO def get(self, i): # TODO if __name__ == "__main__": q = QuickList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) print(q.get(4)) # 5 q.move(3) print(q.get(4)) # 8 q.move(3) print(q.get(4)) # 1 q.move(10) print(q.get(4)) # 1 q.move(7) q.move(5) print(q.get(0)) # 9
Explanation: The contents of the list in the example changes as follows:
move(3)
move(3)
move(10)
move(7)
move(5)