Warning This class is being recorded. At least I think it is.
Approximate overview
Academic
Cultural
Peer
Wellness
Misc
I find it incredibly important to draw pictures whenever I work with linked structures. Consider our linked queues.
front back
| |
v v
+---+---+ +---+---+ +---+---+
| * | *---> | * | *---> | * | / |
+-|-+---+ +-|-+---+ +-|-+---+
v v v
"A" "B" "C"
What should it look like after a call to put("D")
?
front back
| |
v v
+---+---+ +---+---+ +---+---+ +---+---+
| * | *---> | * | *---> | * | *---> | * | / |
+-|-+---+ +-|-+---+ +-|-+---+ +-|-+---+
v v v v
"A" "B" "C" "D"
How do we achieve that?
Node<T> tmp = new Node<T>("D"); // implicit
tmp.next = null;`this.back.next = tmp;
this.back = tmp;
What should it look like after a call to get()
?
tmp front back
| | |
v v v
+---+---+ +---+---+ +---+---+ +---+---+
| * | *---> | * | *---> | * | *---> | * | / |
+-|-+---+ +-|-+---+ +-|-+---+ +-|-+---+
v v v v
"A" "B" "C" "D"
We achieve this with
tmp = this.front;
this.front = this.front.next;
tmp.next = null;
return tmp.value;
Why are we clearing out the tmp.next
?
Note: Drawing pictures of edge cases also helps
if (this.front == null) {
this.back == null;
}
Morals:
Why do we fork and then clone?
So that you have your own copy of the code. You can push your changes and then share them your partner (or yourself on another computer) using the GitHub repo.
How do I know how I’m doing on tokens?
I hope to get that updated next weekend.