Notes for Week 4 / Assignment 4
This gives me the chance to exercise my ASCII skills (though,
I will admit, it's no Star Wars).
Here's one way of thinking of a Queue: it contains two references,
one to the front of the list (called "front") from which elements
are removed, and one to the back of the list (called "back"), to
which elements are added. The Queue itself doesn't worry about
how many QCells might be strung together between those, so it doesn't
explicity keep track of those intermediate QCells.
Let's name the Queue Q for definiteness.
Consider the case when we want to add (enqueue) an element
and there are already some things on the Queue. If the Queue
is empty, that's a special case... .
Here's a BEFORE picture of our nonempty Q:
---
Q is the two references, front and back:
---
------- -----------------------
|front|------> | fr.data | fr.next | // the front cell
------- -----------------/-----
/
/
------- /
|back | |_
------- -----------------------
\ | data | next | // the almost-at-the-
\ -----------------/----- // front cell
| /
| /
| /
| |_
| -----------------------
| | data | next | // the third cell
| -----------------/-----
| /
| /
\ /
\ |_
\ -----------------------
-> |back.data | back.next| // the back cell
-----------------/-----
/
/
/
|_
X (null)
Note that Q.back is NOT null, but Q.back.next IS null.
To add a new cell to the back of the Queue, we would
1) Create a new QCell by calling "new QCell(...)"
- the data in the new QCell is whatever is getting enqueued
- the next QCell after the new QCell will be null, since
the new QCell is going to be the back of the Queue
2) Now, the current Q.back needs to have its "next" reference
updated to refer to the brand new QCell
Q.back.next = <whatever you named the new QCell>
3) Finally, the "back" reference in Q needs to be
updated to refer to the brand new QCell, since it's the
new back...
Q.back = <whatever you named the new QCell>
or
Q.back = Q.back.next (borrowing the right-hand side from step 2)
The AFTER picture of Q would then be
------- -----------------------
|front|------> | fr.data | fr.next | // the front cell
------- -----------------/-----
/
/
------- /
|back | |_
------- -----------------------
\ | data | next | // the almost-at-the-
\ -----------------/----- // front cell
| /
| /
| /
| |_
| -----------------------
| | data | next | // the third cell
| -----------------/-----
| /
| /
| /
| |_
| -----------------------
| | data | next | // the fourth cell
| -----------------/----- // (the old back cell)
| /
| /
\ /
\ |_
\ -----------------------
-> |back.data | back.next| // the back cell
-----------------/-----
/
/
/
|_
X (null)
I hope this does more to help than hinder progress on problem 3!
Because lots of email has been sent out to the cs60 list over the past couple of weeks (and I do acknowledge being the main culprit), I am (from now on) going to post emails sent to the list to web pages linked from the assignment page: http://www.cs.hmc.edu/courses/2000/fall/cs60/assignments/index.html For example, this message is now there in the week 4 page. This way, if you don't want to read the cs-60-l emails, feel free to just delete them and then read them on the web when you get a chance (and if you find you need to). Thanks for the suggestion!
Just a note to let you know assignment 2 is being rereturned, as they are all completely graded. I will _encourage_ the graders to complete AS3 as soon as possible (feel free to add encouragement of your own).
It has been pointed out that there is a typo in the description of the methods "second" and "third" of the OpenList class. They should return the second and third elements of lists, not the first, as the spec describes.
I've received a couple of messages first-hand and several more second-hand about students finding their turing accounts disabled. Over the weekend, the CS staff (completely independent of CS60) checked all of the turing passwords against a list of easy-to-guess passwords. Those that matched were disabled. In order to reenable your account, you should stop by my office this afternoon and we'll try to find a staff member who can help. I should be around until about 5:00.