List
sList
Abstract Data Type (ADT)List
Implementations and TestingDiscussed “task formalizability” in the context of 3 tasks:
Tasks 1, 2, and 3 are increasingly more challenging to formalize
Today. A simpler task!
List
ADTWill’s to-do list:
i
i
i
i
The state of a list is a sequence of elements:
$S = x_0, x_1, x_2, \ldots, x_{n-1}$
$x_i$ represents the element at index $i$
This is a symbolic representation the state of a List
State $S = x_0, x_1, x_2, \ldots, x_{n-1}$
size()
: return n
isEmpty()
: return n == 0
get(i)
: return
$x_i$
i < 0
or i > n-1
State is unchanged after applying these operations
Initial state $S = x_0, x_1, x_2, \ldots, x_{i-1}, x_i, x_{i+1},\ldots, x_{n-1}$
set(i, y)
:
add(i, y)
:
remove(i)
:
Starting from an empty list $S = \varnothing$, perform the following operations:
add(0, "red")
add(1, "orange")
add(2, "yellow")
add(1, "blue")
remove(2)
set(2, "green")
remove(0)
Java interface
allows us to specify required methods
Comments specify intended behavior
See SimpleList.java
List
ImplementationsSimpleList
Java interface
Now what?
How can we represent a List in Java?
List
?Which List operations does an Array support? Which must we implement ourselves?
size()
isEmpty()
get(i)
set(i, y)
add(i, y)
remove(i)
get(i)
and set(i)
?add(i, y)
?remove(i)
?What limitations does an Array have that we have to cope with?
List