ite a method called samePosition in a class called StackExt that receives two parameters st1 and st2 of type ArrayStack and a third parameter pos of type int. The method returns true, if stack st1 and st2 contains the same value in position pos. Otherwise, the method returns false. Assume that both stacks st1 and st2 contain same number of elements. Assume that the position of the top element is 0 and increases by 1 for each subsequent element. The elements of both stacks st1 and st2 must remain in the original relative positions in the stacks at the end of the method. Use common stack operations only such as push, pop, peek, isEmpty, constructor and copy constructor. You can create temporary objects of type ArrayStack in your method. Example: top st1: 4 5 3 10 8 st1: 5 9 4 10 1 If the pos is 3, then both stacks contain 10 in position 3. The method returns true. If the pos is 1, then st1 contains 5 and st2 contains 9 in position 1. The method returns false. public class StackExt { public boolean sameposition(ArrayStack st1, ArrayStack st2, int pos)
rite a method called samePosition in a class called StackExt that receives two parameters st1 and st2 of type ArrayStack and a third parameter pos of type int. The method returns true, if stack st1 and st2 contains the same value in position pos. Otherwise, the method returns false. Assume that both stacks st1 and st2 contain same number of elements.
Assume that the position of the top element is 0 and increases by 1 for each subsequent element. The elements of both stacks st1 and st2 must remain in the original relative positions in the stacks at the end of the method.
Use common stack operations only such as push, pop, peek, isEmpty, constructor and copy constructor. You can create temporary objects of type ArrayStack in your method.
Example:
top
st1: 4 5 3 10 8
st1: 5 9 4 10 1
If the pos is 3, then both stacks contain 10 in position 3. The method returns true.
If the pos is 1, then st1 contains 5 and st2 contains 9 in position 1. The method returns false.
public class StackExt
{
public boolean sameposition(ArrayStack<Integer> st1,
ArrayStack<Integer> st2, int pos)
{
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)