2016-10-28 SuperArray

posted Oct 28, 2016, 6:12 AM by Samuel Konstantinovich   [ updated Oct 28, 2016, 7:37 AM ]
//You should have these:
1. boolean add(int element)
    Appends the specified element to the end of this list. It returns true (add this part)

2. int get(int index)
    Returns the element at the specified position in this list.

3. int    size()
    Returns the number of elements in this list.

4. String toString()

5. String toStringDebug()

//What do you think about these?

//Easy ones:
6. void clear()
    Removes all of the elements from this list.

7. boolean isEmpty()
    Returns true if this list contains no elements.

8. int    set(int index, int element)
    Replaces the element at the specified position in this list with the specified element. Returns the value of the element replaced. 

//harder ones:

9. void add(int index, int element)
    Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

10. int remove(int index)
    Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). The value returned is the value of the element removed.

11. int[] toArray()
    Returns an array containing all of the elements in this list in proper sequence (from first to last element).

12. int indexOf(int i)
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

13. int lastIndexOf(int i)
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

How do you test your SuperArray ?
It is critical to design tests for each method you write to convince you that they work before writing more methods!
If your answer is "I don't know if it works" or "I don't know how to check" then you ABSOLUTELY should not be writing more code!

Comments