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];
}
B)
if (top > -1)
return s[top];
else
throw new RuntimeException("Empty Stack");
You might also like to view...
Which of the following operators are right-associative.
a. * b. + (binary +) c. % d. && e. =
An OpenOffice Calc file is a(n) ________
Fill in the blank(s) with correct word
__________________ is a professor at the University of Missouri, Columbia, who presents a wheel of twenty attributes that all professions ‘should' have.
Fill in the blank(s) with the appropriate word(s).
Wireless Internet access points enable users with computers and mobile devices to connect to the Internet wirelessly.
Answer the following statement true (T) or false (F)