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 peek() operation can be written as
A) if (top == -1)
Throw new RuntimeException("Empty Stack") ;
Else
Return s[top -1];
B) if (top > -1.
Return s[top];
Else
Throw new RuntimeException("Empty Stack".;
C) top --;
If (top == -1.
Throw new RuntimeException("Empty Stack".;
Else
Return s[top];
D) if (top == 0.
Throw new RuntimeException("Empty Stack".;
Else
{
Top --;
Return s[top];
}
Correct Answer:

Verified
Correct Answer:
Verified
Q9: Consider a class that uses the following
Q10: In an implementation of a stack based
Q11: A queue based on a linked list
Q12: In a list implementation of a stack,the
Q13: Compilers of modern programming languages support method
Q15: In an array-based implementation of a stack,an
Q16: The JCF Stack class is used to
Q17: A stack is a container that allows
Q18: A stack based on a linked list
Q19: The operation for removing an item from