
Lecture 6
CSC220: Programming II (Data Structures) - Fall 2002
Dr. Christian A. Duncan
1 Announcements
๎
Read Chapter 4 by next Tuesday.
๎
Quiz this Thursday (on Chapters 1 and 2)
๎
Lab 2 due this Wednesday (at midnight).
๎
Lab 3 due next Wednesday has been posted.
๎
Weโll start class by going overthe implementation details of some more methods in the IntArrayBag Class.
2 Sequence class
The sequence class is very much like the bag class but now the order (or sequence) of the values is important. This
does not mean they are sorted, that is another class. It means they are arranged in a given order. For this version, the
sequence will be stored using an array of doubles. Hence, the name of the class is DoubleArraySeq. Since this
class is one of your programming assignments, we shall go over some of the methods (but not all) briefly. All (but a
few) of the methods are described in more detail in Section 3.3 (page 133-146). And the program stub (API) from the
assignment has the method declarations for all of them. In particular you will need the following:
๎
Constructors: Default (size 10), and one with initial capacity given. Same as with IntArrayBag.
๎
size(): How many elements are in the sequence.
๎
Examining the sequence:
public void start(): Make current point to the start of the sequence
public double getCurrent(): Return the value at the current position in the sequence
public void advance(): Move to the next element in the sequence.
public boolean isCurrent(): Is there a current position? This is useful for cases when the advance
goes beyond the end of the sequence.
๎
Adding to the sequence:
public void addBefore(double element): Add element to the sequence before the current posi-
tion.
public void addAfter(double element): Add element to the sequence after the current position.
๎
removeCurrent(): Remove the current element from the sequence.
๎
Merging sequences
void addAll(DoubleArraySeq addend): Adds the addend to the end of the (this) sequence.
public static DoubleArraySeq concatenation(DoubleArraySeq s1, DoubleArraySeq
s2):
Combines the two sequences together into a new sequence... very similar to the union() method of IntArray-
Bag.
๎
Cloning: Using clone(), to make an exact duplicate of the sequence.
Basically, the code is standard for this and I believe even included in the source stub.
Note this is not all of them nor did I mention all the details like pre-condition and post-condition here. But we
shall scan over most of them in class.
1