Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A StringBag Abstract Data Type (ADT) is a simple collection of strings ordered by time of entry (not alphabetical) . Like a stack, the last

A StringBag Abstract Data Type (ADT) is a simple collection of strings ordered by time of entry (not alphabetical) . Like a stack, the last string entered goes on the top. The strings are not alphabetized in the bag.

Client programs can insert string s into the bag , check its size, clear it, use its toString , remove the top string, and check to see i f it is full. W e want to k eep things simple, so we allow duplicates. There is no provision to see if a given string is already in the b ag. Further, the client can only remove the st r ing on top , like a stack . The StringBag is a LIFO collection. See the StringBagInterface , below.

Create a class to implement the interface using a private linked lis t to hold the inserted strings.

Note: if the list is not empty, then the following code wi ll remove the first item in a linked list: head = head.getLink( ) ; Design a test driver that show s that your St ringBag.java class works correctly.

public interface StringBagInterf ace {

void insert(String element);

// Precondition : This StringBag is not full.

// Places element into this StringLog.

boolean isFull();

// Returns true if this StringBag is full, otherwise returns false.

boolean isEmpty();

// Re turns true if this StringBag contains no strings.

int size();

// Returns the number of Strings in this StringBag.

String remove();

// Precondition: the Bag is not empty

// Removes the string at the top of t he bag and returns it.

void clear();

// Makes this StringBag empty.

String getName();

// Returns the name of this StringBag

String toString();

// Returns a nicely for matted string representing the

// name of the bag and all of its contents.

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions