Review of yesterday's
My possible solution is on this branch: https://github.com/githubdudu/react-study-group/tree/day2-solution
- This way of
addLast is very inefficient because we have to iterator all the elements in the list.
@Override
public void addLast(Object item) {
add(size, item);
}
We shall directly use sentinel.prev to get the last element. By using sentinel, we implement the DLL as a circle.
@Override
public void addLast(V item) {
// TODO: make this method as efficient as possible
Node newNode = new Node(item, sentinel.prev, sentinel);
sentinel.prev.next = newNode;
sentinel.prev = newNode;
size++;
}
-
We can utilize the generic to finish task 2. Object type is not a better way. :-)

-
You may notice there is an error in JavaScript version. To fix this error, we must either rename the size() function or rename the this.size property.
This is because in the class of JS, property and function are all treated as objects. An override will happen if there is a same-name declaration.
Review of yesterday's
My possible solution is on this branch: https://github.com/githubdudu/react-study-group/tree/day2-solution
addLastis very inefficient because we have to iterator all the elements in the list.We shall directly use
sentinel.prevto get the last element. By using sentinel, we implement the DLL as a circle.We can utilize the generic to finish task 2. Object type is not a better way. :-)
You may notice there is an error in JavaScript version. To fix this error, we must either rename the
size()function or rename thethis.sizeproperty.This is because in the class of JS, property and function are all treated as objects. An override will happen if there is a same-name declaration.