Question: Write a method called alternatingReverse that takes a stack of integers as a parameter and that rearranges the values so that every other value strting

Write a method called alternatingReverse that takes a stack of integers as a parameter and that rearranges the values so that every other value strting from the bottom of the stack is reversed in order. Assuming the size is always even (as the example below), your method always checks and throws an IllegalArgumentException.

For example if a varable s stores these values:

bottom[1, 2, 3, 4, 5, 6, 7, 8]top; your program alternatingReverse(s) will reverse the odd numbers of the sequence from this to:

bottome[7, 2, 5, 4, 3, 6, 1, 8]top

where s is a Stack

Hint* Starting from the bottom of the stack and looking at every other value, we find the sequence of numbers 1, 3, 5, 7. This sequence should be reversed while the other values should stay in the same positions. If we make the following call:

alternatingReverse(s);

the stack should store th efollowing values after the call:

bottom[7, 2, 5, 4, 3, 6, 1, 8]top

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!