Solved

Consider a Class That Uses the Following Variables to Implement

Question 1

Multiple Choice

Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
Int top = 0;
A method that implements the String peek() operation can be written as


A) return s[top];
B) if (top == 0.
Throw new RuntimeException("Underflow".;
Else
Return s[top];
C) if (top == 0.
Throw new RuntimeException("Underflow".;
Else
Return s[top-1];
D) return s[top-1];

Correct Answer:

verifed

Verified

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents