Overview
I hear that there are some questions about removal. Please ask them.
How do we tell what to remove?
Semantics: Remove what was returned by the most recent call to
previous
ornext
.
We must therefore have a field that stores the information about which direction we just moved.
Option 1:
int dir; // Use pos for forward and neg for backwards.
Option 2: Keep a pointer to the thing we will remove or set when we call remove or set.
In (all) options, we will still need to update the state of the iterator. If we remove the previous element (because we just called
next
), we’ll need to decrement the position in the list. If we are using a linked structure, we will likely need to change theprev
link.
What happens when we remove in an array-based list?
Traditionally, we shift everything to the left.
If the thing we remove is before the cursor/iterator, we should decrement the position by 1.
Did you inform the people who didn’t format correctly?
Thu: Yes. Sun: No.
Should we turn in new epilogues if we took advantage of the free extension?
Yes. Your times probably changed. Maybe you learned something else.
Where does pos
start?
It depends on the interpretation of the pos. I generally use pos as “position of the next element”. I would therefore start it at 0.
Some folks take the “between elements” way to seriously and start it at -0.5.
How do we remove in a doubly-linked list?
Conceptual: The cursor refers to previous and next, for convenience.
We know which element to remove because we’ve stored that information. Suppose it’s the previous element (because we’ve called
next
).
We are going to update the list, so we may need to update the cursor’s prev link.
prev = update.prev;
We need to change the surrounding pointers.
update.prev.next = update.next;
update.next.prev = update.prev
We may want to clear the pointers (helps avoid later problems)
update.prev = null
update.next = null;
If we’re keeping track of the position (and we should) we decrement it by 1.
Set
update
to null so that we don’t allow subsequent updates.
Special case: If we removed the first element in the list, we need to update front.
The code seems to mimic this approach.
Sam needs an editor (no, not vi
). The first line of problem 1 says
“each of the two primary list iterations”; it means “each of the two
primary list *implementations*.