Docsity

Exam for Quiz 1 - Data Structures | COP 3530, Quizzes of Data Structures and Algorithms

Toggle sidebar
bg1
Quiz #1B
Name
:
READ THE QUESTIONS CAREFULLY!!! DO NOT WASTE TIME DOING
MORE THAN IS ASKED FOR. DO NOT IMPLEMENT METHODS UNLESS SPECI-
FICIALLY REQUESTED. YOU DO NOT NEED TO COMMENT THE CODE.
1. Write an
interfae
op3530.Set
with the publi methods below. (This is a dierent interfae
than what you wrote for program 1, but the priniples are idential.)
Set
is the name of the
interfae that stores
Objet
s (NOT pairs) that has the following funtionality:
Three aessors:
ontains
returns true if a speied ob jet is found in the set; returns
false otherwise.
isEmpty
, tests if the
Set
is empty; and
size
returns the number of
elements urrently stored in the
Set
ontainer.
Two mutators: One mak
es the
Set
empty; the other (
add
) inserts a new item.
2. Provide a lass
op3530.SortedArraySet
that implements the
Set
interfae. Represent the
SortedArray
internally as a (sorted)
Objet[℄
, a
size
data member, and a
Comparator
.
After listing the data elds, you may use
...
to indiate the rest of the body of this lass,
exept for the following whih must be implemented:
(a) Implemen
t a zero parameter onstrutor; your implementation may assume the existene
of a one-parameter onstrutor that takes a
Comparator
as a parameter. Make sure you
provide the lass delaration for the default omparator that you will need.
(b) Implement
ontains
.
In y
our implementation, you should use a sequential
searh. If you nd an item in the array that is larger than the item b eing
searh for, you should immediately return
false
.
1

Partial preview of the text

Download Exam for Quiz 1 - Data Structures | COP 3530 and more Quizzes Data Structures and Algorithms in PDF only on Docsity!

Quiz #1B

Name:

READ THE QUESTIONS CAREFULLY!!! DO NOT WASTE TIME DOING MORE THAN IS ASKED FOR. DO NOT IMPLEMENT METHODS UNLESS SPECI- FICIALLY REQUESTED. YOU DO NOT NEED TO COMMENT THE CODE.

  1. Write an interfa e op3530.Set with the publi metho ds b elow. (This is a di erent interfa e than what you wrote for program 1, but the prin iples are identi al.) Set is the name of the interfa e that stores Obje ts (NOT pairs) that has the following fun tionality:

 Three a essors: ontains returns true if a sp e i ed ob je t is found in the set; returns false otherwise. isEmpty, tests if the Set is empty; and size returns the numb er of elements urrently stored in the Set ontainer.  Two mutators: One makes the Set empty; the other (add) inserts a new item.

  1. Provide a lass op3530.SortedArraySet that implements the Set interfa e. Represent the SortedArray internally as a (sorted) Obje t[℄, a size data memb er, and a Comparator. After listing the data elds, you may use ... to indi ate the rest of the b o dy of this lass, ex ept for the following whi h must b e implemented:

(a) Implement a zero parameter onstru tor; your implementation may assume the existen e of a one-parameter onstru tor that takes a Comparator as a parameter. Make sure you provide the lass de laration for the default omparator that you will need. (b) Implement ontains. In your implementation, you should use a sequential sear h. If you nd an item in the array that is larger than the item b eing sear h for, you should immediately return false.