int mid = list.size() / 2;
ListIterator<E> iter = list.listIterator();
int i = 0;
- // go to the element at mid index
- while (iter.hasNext() && i < mid) {
+ // go to the element at mid + 1 index
+ while (iter.hasNext() && i <= mid) {
iter.next();
i++;
}
- iter.next(); // Insert before mid + 1
iter.add(value);
}
public void addNEMiddle(int Nelements) {
ListIterator<E> iter = list.listIterator();
int i = 0;
- // go to the element at the middle index
- while (iter.hasNext() && i < list.size() / 2) {
+ // go to the element at the middle + 1 index
+ while (iter.hasNext() && i <= list.size() / 2) {
iter.next();
i++;
}
- iter.next(); // Insert before mid + 1
for (int j = 0; j < Nelements; j++) {
iter.add((E)new Object());
}