Question: java problems Question 3 Implement the class method: public static void swap(Stack xs , Stack ys) The method exchanges the content of two stacks, xs
java problems
Question 3
Implement the class method: public static
The method exchanges the content of two stacks, xs and ys.
ThemethodmustworkforanyvalidimplementationoftheinterfaceStack;
You can assume the existence of the classes DynamicArrayStack and LinkedStack.
Stack
swap(a, b); System . out . p r i n t l n ( a ) ; System.out. println(b);
In particular, the above statements should print the following.
[gamma, beta , alpha ] [ black , yellow , green , blue ]
[ black , yellow , green , blue ]
[gamma, beta , alpha ]
Write the code for this method with the following signature: public static
Question 4
Complete the implementation of the instance methods size() and swap() within the class LinkedStack below.
Themethodsize()returnsthenumberofelementsthatarecurrentlystored into this stack
The method swap exchanges the first two elements (not the values); the first element becomes the second and the second element becomes the first. The method returns false if there are less than 2 elements in the list. You cannot use the methods push and pop, instead the links of the structure (references) must be transformed.
public class LinkedStack
private class Elem
private Elem
private Elem(E info , Elem
} }
private Elem
public int size () {}
public boolean swap() {} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
