I am building a program that uses a doubly linked list to build a stack. I am required to flip the stack, or reverse the order of it, with a runtime of O(1). For instance:
1 -> 2 -> 3 -> 4
becomes
4 -> 3 -> 2 -> 1
The fastest way I can think of uses O(N) as a runtime. By being required to use a runtime of O(1) all loops are out of the question, as they will all inevitably depend on the number of nodes in the stack.
Can anybody recommend a reasonable way to go about this problem?