Homework: Stack and Sequence Flip
-
Implement the
Stackfamily instance methodflipdeclared as follows (thisis aStack<T>):/** * Reverses ("flips") {@code this}. * * @updates this * @ensures this = rev(#this) */ public void flip(); -
Implement the
Sequencefamily instance methodflipdeclared as follows (thisis aSequence<T>):/** * Reverses ("flips") {@code this}. * * @updates this * @ensures this = rev(#this) */ public void flip(); -
Provide a second, different implementation of the instance method
flipforSequence<T>. If your first implementation is iterative (i.e., uses a loop), your second one should be recursive and vice versa.