Solved

Consider a Class That Uses the Following Variables to Implement

Question 25

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 pop() operation can be written as


A) if (top == 0)
Throw new RuntimeException("Underflow") ;
Top--;
String temp = s[top];
S[top] = null;
Return temp;
B) if (top == 0.
Throw new RuntimeException("Underflow".;
String temp = s[top];
Top--;
S[top] = null;
Return temp;
C) if (top == 0.
Throw new RuntimeException("Underflow".;
Return s[top-1];
Top --;
S[top] = null;
D) top--;
Return s[top];

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions