Solved

Consider a Class That Uses the Following Variables to Implement

Question 6

Multiple Choice

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


A) if (top == -1)
Throw new RuntimeException("Empty Stack") ;
Top --;
String temp = s[top];
S[top] = null;
Return temp;
B) if (top == -1.
Throw new RuntimeException("Empty Stack".;
S[top] = null;
Top--;
Return s[top ];
C) if (top == -1.
Throw new RuntimeException("Empty Stack".;
String temp = s[top];
S[top] = null;
Top--;
Return temp;
D) None of the above

Correct Answer:

verifed

Verified

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

Related Questions