Question 1 Consider a class that uses the following variables to implement an ar
ID: 3703118 • Letter: Q
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 // 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]Explanation / Answer
option a is the correct. While inserting element in the stack, value of top increments then we will insert the value. So, the value of -top contains the last value entered.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.