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 void push(String x) operation can be written as
A)
if (top == s.length-1)
throw new RuntimeException("Overflow");
top++;
s[top] = x;
B)
if (top == s.length)
throw new RuntimeException("Overflow");
top++;
s[top] = x;
C)
if (top == s.length-1)
throw new RuntimeException("Overflow");
s[top] = x;
top++;
D)
if (top == s.length)
throw new RuntimeException("Overflow");
s[top] = x;
top++;

A)
if (top == s.length-1)
throw new RuntimeException("Overflow");
top++;
s[top] = x;

Computer Science & Information Technology

You might also like to view...

____________ is a service offered by Google that checks URLs against a list of suspicious Web site URLs.

A. Personal firewall B. Safe Browsing C. Heuristic analysis D. SmartScreen Filter

Computer Science & Information Technology

Explain how a mantrap works.

What will be an ideal response?

Computer Science & Information Technology