Purchase Solution

Java List Arrays Example: Class SList

Not what you're looking for?

Ask Custom Question

Use the following shell class SList, and complete its implementation as per the guidance in points 1 through 5. Read the documentation on the member function declarations carefully.

public class SList
{
// Methods
public void insert(int item);
// Pre: The list is not full
// item is not in the list
// Post: item is in the list; the items are in sorted order
public void printList()
// Post: If the list is not empty, the elements are
// printed on the screen; otherwise "The list
// is empty" is printed on the screen
public int getLength()
// Post: return value is the number of items in the list
public boolean isEmpty()
// Post: returns true if list is empty; false otherwise
public boolean isFull()
// Post: returns true if there is no more room in the
// list; false otherwise
SList(int maxItems)
// Constructor
// Post: Empty list is created with maxItems cells
// Data fields
private int numItems;
private int[] values;
}

1: Write the definitions for the member functions.

2: Write a driver program that reads values from file int.dat, stores them in the list, and prints them on the screen.

3: Add a boolean method "contains" to class SList that returns true if its parameter is in the list and false otherwise. Use the binary search algorithm.

4: Add a private variable currentItem to the list and implement these method headings. This combination allows the user to view the list items, one at a time.

public void resetList()
// Set currentItem to 0
public String next()
// Returns the item at values[currentItem]
// Increments currentItem
public boolean hasNext()
// Returns true if currentItem is not equal to numItems

5: Augment the driver in point 2 to demonstrate how to use resetList, hasNext, and next to print the list.

Purchase this Solution

Solution Summary

This solution provides a detailed explanation of the given computer science assignment regarding the class SList.

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.