ArrayIntList.java - implement an ArrayIntList which is an...

This preview shows page 1 out of 3 pages.

/* * implement an ArrayIntList which is an ordered list of int * provide access to element at specific index * Implement methods lastIndexOf(int) and indexOfSubList(ArrayIntList) */ import java.util.Arrays; public class ArrayIntList { // instance variable private int[] elementData; private int size; public static final int DEFAULT_CAPACITY = 10; public ArrayIntList(){ this(DEFAULT_CAPACITY); } public ArrayIntList(int defaultCapacity) { // TODO Auto-generated constructor stub elementData = new int[DEFAULT_CAPACITY]; size=0; } // post: return number of elements in the list public int size(){ return size; } // return index of 1st instance of a given value // -1 if the value not in the list public int indexOf(int value){ for(int i=0; i<size; i++){ if(value==elementData[i]) return i; } return -1; } // ad d a given value to the end of list public void add(int value){ add(size, value); } // pre: 0<=index<=size, throw indexoutofbound exception // otherwise // post: shifting all elements to the right to put it there private void add(int index, int value) { // TODO Auto-generated method stub
Image of page 1
You've reached the end of this preview.
  • Spring '15
  • Villarba

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern