X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=exo2%2FListExtension.java;h=20e9fb22afd422316d1301fed7ef391402b69ed5;hb=3b1969267fdc47fa2abbd459d3ab1306b294bdb3;hp=bba85d2fb1c60307cdf0d25333d18f6de501fb5d;hpb=01bad5b37bf95f027f583e1b1da607e074050651;p=Project_POO.git diff --git a/exo2/ListExtension.java b/exo2/ListExtension.java index bba85d2..20e9fb2 100644 --- a/exo2/ListExtension.java +++ b/exo2/ListExtension.java @@ -32,33 +32,36 @@ public class ListExtension { return list.add(e); } + public int size() { + return list.size(); + } + /** - * Should mimic the List add(int index, T value) method - * @param value [description] - * @return [description] + * Should mimic the List add(int index, E value) method + * @param index [description] + * @param value [description] + * @return [description] */ - public void addMiddleIter(E value) { - int mid = list.size() / 2; + public void addIter(int index, E value) { ListIterator iter = list.listIterator(); int i = 0; - // go to the element at mid index - while (iter.hasNext() && i < mid) { + // go to the element at index + 1 + while (iter.hasNext() && i <= index) { iter.next(); i++; } - iter.next(); // Insert before mid + 1 iter.add(value); } - public void addNEMiddle(int Nelements) { + //FIXME: replace parameter by the list of objects to add + public void addNelements(int index, int Nelements) { ListIterator 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 index + 1 + while (iter.hasNext() && i <= index) { iter.next(); i++; } - iter.next(); // Insert before mid + 1 for (int j = 0; j < Nelements; j++) { iter.add((E)new Object()); }