Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Yi index =-1; 9 S2 9 0 9 0 11 2 Refer to the following code, implement the method: public NumStack join(NumStack s) public class
Yi index =-1; 9 S2 9 0 9 0 11 2 Refer to the following code, implement the method: public NumStack join(NumStack s) public class NumStack implements Comparable{ ments compa private Integer[] data; public NumStack join(numstack s) joins DPYRIGHT two stack from the bottom of each stack, private int index; for example, s1[2,0, 9] and s2[9,0,9], IT public NumStack(int cap) { calling s1.join(s2) should return a data=new Integer[cap]; NumStack which contains[11,0,18], COPYRIGHT s1 Returned NumStack } top 18 public boolean isEmpty() { return index == -1; bottom * == -1;RIGHT } public boolean is Full() { return index==data.length -1; } If the two stacks have different sizes, public NumStack pop() { then we just push extra items from the if(!isEmpty()) data[index-- ]=null; larger size stack to the resulting stack. return this; For example, $1[8,0, -9] and s2[1], } calling $1.join(52) should return COPY public int size(){ NumStack as follows: return index+1; s1 Resulting stack (returned) public Integer top(){ PYRIGHT top -9 if(isEmpty()) return null; return data[index]; bottom 8 1 public NumStack push(int num) { COPYRIGHT if(index
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started