Explore BrainMass

Explore BrainMass

    Java List Arrays Example: Class SList

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    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.

    © BrainMass Inc. brainmass.com May 20, 2020, 7:23 pm ad1c9bdddf

    Solution Summary

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