Lists -- How to Build Your Own - University of Michigan
Lists -- How to Build
Your Own
Atul Prakash
Reference: Look at ArrayList.java implementation in Java
Source:
Class MyList
?
?
Implement a list using
arrays
?
?
?
?
Methods:
?
?
?
Constructors: default
capacity and given
capacity
add(Object element)
Object get(int index)
remove element:
?
last
first
at a given position
size(): returns size
Some tests
import junit.framework.*;
public class MyListTest extends TestCase {
public void testCount() {
MyList l = new MyList();
assertEquals(0, l.size());
l.add("abc");
l.add("def");
l.add(3);
assertEquals(3, l.size());
}
public void testInserts() {
MyList l = new MyList();
l.add("abc");
l.add("def");
l.add(3);
assertEquals(3, l.get(2));
assertEquals(3, l.size());
// String s = l.findElement(0); // cast needed.
// assertEquals("abc", s);
}
}
List State Variables
public class MyList { // list of integers
Object[] data; // list itself. null values at the end
int capacity; // maximum capacity of the list
int num; // current size of the list
static final int DEFAULT_CAPACITY = 100;
Invariants:
num = # of elements in the list.
0 ................
................
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
- cs106a stanford handout 49 fall 2004 05 nick parlante
- chapter 19 java data structures
- ch7 list and iterator adts
- arrays and arraylists
- big o arraylist carnegie mellon university
- arrays stanford university
- arraylist reading 10
- arraylist in java
- java arraylist copyright © tutorialspoint
- building java programs chapter 10
Related searches
- how to make your own tea
- how to get your own email address
- how to start your own business
- how to file your own taxes
- how to start your own business ideas
- how to sell your own home yourself
- how to make your own business
- how to start your own online business
- how to open your own business
- how to make your own song
- how to make your own music
- how to make your own email address