Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public int size() { if (rest == null) return 1; return 1 + rest.size(); } Given the following StringStack wrapper class: public class StringStack {

public int size() { if (rest == null) return 1; return 1 + rest.size(); } 

Given the following StringStack wrapper class:

public class StringStack { private InternalStringStack stack; public StringStack() { // Create an empty stack stack = null; } public void push(String s) { stack = new InternalStringStack(s, stack); } public String top() { if (stack == null) return null; return stack.getData(); } } 

Which of the following implementations of size will work for the StringStack wrapper class? The size method should return the number of items (String objects) in the represented stack structure and should work correctly for empty and non-empty stacks.

public int size() { return stack.size(); } 
public int size() { return stack.size() + 1; } 
public int size() { if (stack == null) return 0; return stack.size(); } 
public int size() { if (stack == null) return 0; return stack.size() + 1; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

=+you think is being taxed when more money is printed? Why?

Answered: 1 week ago