CSE116 / CSE504 Introduction to Computer Science II Dr. Carl Alphonce

advertisement
CSE116 / CSE504
Introduction to Computer Science II
Dr. Carl Alphonce
343 Davis Hall
alphonce@buffalo.edu
Office hours:
Thursday 12:00 PM – 2:00 PM
Friday 8:30 AM – 10:30 AM
OR request appointment via e-mail
PROFESSIONALISM
Turn off and put away electronics:
cell phones
pagers
laptops
tablets
etc.
© Dr. Carl Alphonce
ROADMAP
Last class
java.util.LinkedList exercise: add
Today
java.util.LinkedList exercise: remove
Wednesday
asymptotic notation
Friday
exam Q&A session (bring questions!)
Exam #1
EXAM INFORMATION
Tuesday 3/8, 9:15 PM - 10:15 PM
Will cover material up to 2/26 (as well as WU3)
If you have a legitimate conflict (work/school):
get documentation, scan it as a PDF
e-mail it to me with subject line:
[CSE116] Exam 1 conflict documentation
NO LATER THAN 5:00 PM on 3/4 (FRIDAY)
WEDNESDAY 3/9 IS EXAM MAKE-UP DAY:
NO REGULAR LECTURE
© Dr. Carl Alphonce
public boolean remove(Object o) {
if (o == null) {
for (Node<E> x = first; x != null; x = x.next) {
if (x.item == null) {
unlink(x);
return true;
}
}
} else {
for (Node<E> x = first; x != null; x = x.next) {
if (o.equals(x.item)) {
unlink(x);
return true;
}
}
}
return false;
}
E unlink(Node<E> x) {
E element = x.item;
Node<E> next = x.next;
Node<E> prev = x.prev;
if (prev == null) {
first = next;
} else {
prev.next = next;
x.prev = null;
}
if (next == null) {
last = prev;
} else {
next.prev = prev;
x.next = null;
}
x.item = null;
size--;
modCount++;
return element;
}
Exercises
1. Draw an object diagram showing:
LinkedList<String> names = new LinkedList<String>();
names.add(“Mal”);
names.add(“River”);
names.add(“Zoë”);
names.add(“Kaylee”);
names.add(“Jayne”);
2. Draw object diagrams showing what happens in each
step:
names.remove(“Mal”);
names.remove(“Jayne”);
names.remove(“Zoë”);
Download