Question: Question 1 Consider a class that uses the following variables to implement an array-based stack string [ ] s new String[100]; int top1; ation //

Question 1 Consider a class that uses the following variables to implement an array-based stack string [ ] s new String[100]; int top1; ation // Note top =-1 indicates stack is empty a method that implements a String peek() operation can be written as oa top - if (top #-1) throw new RuntimeException("Empty Stack") return s[top]: else -83448 throw new RuntimeException("Empty Stack"); else top return s[top]: oc.if (top> 1) return s[top]: else throw new RuntimeException( "Empty Stack"); od.if (top1) throw new RuntimeException("Empty Stack"); else return s [top -1]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
