I have been asked to design a data structure which will act like a stack, not limited in size, which will support the following methods, with given run-time restrictions.
push(s) - push s to the data structure - O(1) pop() - remove and return the last element inserted O(1) middle() - return the element (without removing) with index n/2 by insertion order where n is the current amount of elements in the data structure. - O(1) peekAt(k) - return the kth element by insertion order (the bottom of the stack is k=1) - O(log(k))
the 3 methods will use a linked list, but how i should implement the method peekAt(k).
thank you.