Here is a simpler version of the add(Object, int) method from Section 3.4.9. Under what circumstances will it fail? How do you fix this problem?
```
1 public void add( E e, int p ) {
2 if (( p < 0 ) || ( p > length ) )
3 throw new IndexOutOfBoundsException();
4 SLNode
5
6 SLNode
7 addAfter( cursor, newnode );
8 length++;
9 }
```
If index is 0, find(index - 1) will cause an error (0-1 = -1). Here is the correction:
if ( p > 0 )
SLNode
else
SLNode
You might also like to view...
A combination of keys that perform a command, such as Ctrl + I, is called a keyboard ________
A) rule B) shortcut C) function D) task
If host A is able to successfully ping router R1 but not router R2, which of the following is guaranteed?
A) Port security is not filtering frames sent between host A and R1. B) Port security is filtering frames sent by R2. C) R2 itself is down. D) STP has not placed the right ports in a forwarding state.
What are the four JFrame constructors?
What will be an ideal response?
What is a major advantage of DeviceNet, an open network intended to link low-level devices?
What will be an ideal response?