An Array-Based Implementation of the ADT List
An Array-Based Implementation of the ADT List
public class ListArrayBased implements ListInterface {
private static final int MAX_LIST = 50; private Object items[];
// an array of list items
private int numItems;
// number of items in list
An Array-Based Implementation of the ADT List
public ListArrayBased() { items = new Object[MAX_LIST]; numItems = 0;
} // end default constructor
An Array-Based Implementation of the ADT List
public boolean isEmpty() { return (numItems == 0);
} // end isEmpty
public int size() { return numItems;
} // end size
Insertion into Array
What happens if you want to insert an item at a specified position in an existing array?
Write over the current contents at the given index (which might not be appropriate), or The item originally at the given index must be moved up one position, and all the items after that index must shuffled up
An Array-Based Implementation of the ADT List
public void add(int index, Object item) throws ListException,
ListIndexOutOfBoundsException { if (numItems >= MAX_LIST) {
throw new ListException("ListException on add:"+
" out of memory");
} // end if if (index < 1 || index > numItems+1) {
// index out of range throw new ListIndexOutOfBoundsException(
"ListIndexOutOfBoundsException on add");
} // end if
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- cmsc 341 lecture 7 stl containers iterators algorithms
- amd raid configuration guide
- javascript arrays object biggest online tutorials library
- algorithms princeton university
- csc 273 data structures adelphi university
- powershell basic cheat sheet rambling cookie monster
- mathcad tutorial university of connecticut
- lab 6k a shopping cart using the class lab 6k a shopping cart using
- java built in arrays university of san francisco
- big o arraylist carnegie mellon university
Related searches
- length of an array javascript
- length of an array python
- length of an array matlab
- create a copy of an array javascript
- sort an array of int
- creating an array of objects
- json send an array of object
- to what extent did the decade of the 1950s deserve its reputation as an age of p
- create an array of size python
- how to create an array of objects
- books of the bible list pdf
- books of the bible list printable chart