Presentation is loading. Please wait.

Presentation is loading. Please wait.

Implementation options There are two basic approaches: –array-based –linked We will consider array-based implementation first Use a TDD approach: first.

Similar presentations


Presentation on theme: "Implementation options There are two basic approaches: –array-based –linked We will consider array-based implementation first Use a TDD approach: first."— Presentation transcript:

1 Implementation options There are two basic approaches: –array-based –linked We will consider array-based implementation first Use a TDD approach: first consider what the essential functionality of a given ADT is.

2 Arrays An array is a collection of variables, all of the same type. An array is created with the new operator. The size of an array must be specified at creation time. The memory for an array is allocated in a contiguous block. The size of an array is fixed.

3 Array indexing A variable in an array is accessed using special syntax. –Suppose Object[] x = new Object[4]; –Variables: x[0], x[1], x[2] and x[3] –Index ranges from 0 to size-1.

4 Generics You’ve seen how to use generic collections in CSE115. We’ll discuss how to define them in more detail later – don’t sweat these details just now.

5 Collection interface We’ll set up our Bag implementation to implement the java.util.Collection interface. Method signatures come from this interface. We will not look at all the required methods today, only the four identified earlier: –add, remove, contains and size

6 eclipse Define constructor, add and size to get our test to pass. One important issue that came up in classroom discussion is the difference between the CAPACITY of the array (its length) and the SIZE of the Bag (how many items it contains).


Download ppt "Implementation options There are two basic approaches: –array-based –linked We will consider array-based implementation first Use a TDD approach: first."

Similar presentations


Ads by Google