Solved

Consider a Class That Uses the Following Variables to Implement

Question 26

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 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 ++;

Correct Answer:

verifed

Verified

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

Related Questions