Question: Implement the following method that, given two stacks and an integer, moves entries between the two stacks so that the length of the first stack

Implement the following method that, given two stacks and an integer, moves entries between the two stacks so that the length of the first stack is equal to the given integer. Note that, as the ensures clause states, rev(leftStack) * rightStack must not be changed by the method.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

/**

* Shifts entries between {@code leftStack} and {@code rightStack}, keeping

* reverse of the former concatenated with the latter fixed, and resulting

* in length of the former equal to {@code newLeftLength}.

*

* @param

* type of {@code Stack} entries

* @param leftStack

* the left {@code Stack}

* @param rightStack

* the right {@code Stack}

* @param newLeftLength

* desired new length of {@code leftStack}

* @updates leftStack, rightStack

* @requires

* 0 <= newLeftLength and

* newLeftLength <= |leftStack| + |rightStack|

*

* @ensures

* rev(leftStack) * rightStack = rev(#leftStack) * #rightStack and

* |leftStack| = newLeftLength}

*

*/

private static void setLengthOfLeftStack(Stack leftStack,

Stack rightStack, int newLeftLength) {...}

Note that setLengthOfLeftStack is a static, generic method: it is parameterized by the type T of the entries in the stacks. You can use the type T wherever you need to declare a variable that refers to an object of type T.

Develop a complete test plan for the Sequence constructor and kernel methods (add, remove, and length) and enter them in SequenceTest.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!