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
Q24: In a queue implementation that uses an
Q25: A stack based on a linked list
Q26: Consider a class that uses the following
Q27: In an implementation of a stack based
Q28: The operation for removing an item from
Q30: A queue based on a linked list
Q31: A queue invariant is a condition
A) obeyed
Q32: The operation for adding an item to
Q33: Which of the following operations is not
Q34: A queue based on a linked list
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents