Tips and Common Points of Confusion
How to Get Started
Stuck on LinkedListDeque and/or ArrayDeque? One great first step is implementing SList and/or AList. Starter code can be found in:
To make this more time efficient:
How to Get Started (Part 2)
Try implementing just the empty Deque, and compare your data structure to the idea developed in class.
Compare the output of your code using the visualizer.
Other General Tips
Take things a little at a time.
If your first try goes badly, don’t be afraid to scrap your code and start over.
Consider not doing resizing at all until you know your code works without it.
Common Point of Confusion
Any time I drew an arrow in class that pointed at an object, the pointer was to the ENTIRE object, not a particular field of an object.
sentinel
5
2
size
17
??
next
item
prev
insertBack()
getBack()
size()
deleteBack()
Examples:
Circular ArrayDeque Demo
ArrayDeque Tips
Starting from an empty ArrayDeque:
addLast()
addFirst()
items
4
nextFirst
5
nextLast
0 1 2 3 4 5 6 7
0
size
ArrayDeque Tips
Starting from an empty ArrayDeque:
addLast()
addFirst()
items
4
nextFirst
a
6
nextLast
0 1 2 3 4 5 6 7
1
size
ArrayDeque Tips
Starting from an empty ArrayDeque:
addLast()
addFirst()
items
4
nextFirst
a
b
7
nextLast
0 1 2 3 4 5 6 7
2
size
ArrayDeque Tips
Starting from an empty ArrayDeque:
addLast()
addFirst()
items
3
nextFirst
c
a
b
7
nextLast
0 1 2 3 4 5 6 7
3
size
ArrayDeque Tips
Starting from an empty ArrayDeque:
addLast()
addFirst()
items
3
nextFirst
c
a
b
d
0
nextLast
0 1 2 3 4 5 6 7
4
size
ArrayDeque Tips
Starting from an empty ArrayDeque:
addLast()
addFirst()
items
e
3
nextFirst
c
a
b
d
1
nextLast
0 1 2 3 4 5 6 7
5
size