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)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

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)

 {

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning