


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















data object
set or collection of instances
integer = {0, +1, -1, +2, -2, +3, -3, …}
daysOfWeek = {S,M,T,W,Th,F,Sa}
instances may or may not be related
The relationships are usually specified by specifying operations on one or more instances.
add, subtract, predecessor, multiply
Students in COP3530 =
(Jack, Jill, Abe, Henry, Mary, …, Judy)
Exams in COP3530 =
(exam1, exam2, exam3)
Days of Week = (S, M, T, W, Th, F, Sa)
Months = (Jan, Feb, Mar, Apr, …, Nov, Dec)
get element with given index
L = (a,b,c,d,e) get(0) = a get(2) = c get(4) = e get(-1) = error get(9) = error
determine the index of an element
L = (a,b,d,b,a)
indexOf(d) = 2
indexOf(a) = 0
indexOf(z) = -
remove and return element with given index
L = (a,b,c,d,e,f,g)
remove(-1) => error remove(20) => error
add an element so that the new element has a specified index
L = (a,b,c,d,e,f,g)
add(0,h) => L = (h,a,b,c,d,e,f,g)
index of a,b,c,d,e,f, and g increase by 1
Abstract Data Type
Interface Abstract Class
AbstractDataType LinearList { instances ordered finite collections of zero or more elements operations isEmpty() : return true iff the list is empty, false otherwise size(): return the list size (i.e., number of elements in the list) get(index) : return the index th element of the list indexO f(x) : return the index of the first occurrence of x in the list, return -1 if x is not in the list remove(index) : remove and return the index th element, elements with higher index have their index reduced by 1 add(theIndex, x) : insert x as the index th element, elements with theIndex >= index have their index increased by 1 output() : output the list elements from left to right }
public interface LinearList { public boolean isEmpty(); public int size(); public Object get(int index); public int indexOf(Object elem); public Object remove(int index); public void add(int index, Object obj); public String toString(); }
public class ArrayLinearList implements LinearList { // code for all LinearList methods must be provided here }