diff --git a/exercises/lists1/IntList.java b/exercises/lists1/IntList.java index 09493cf..27232e7 100644 --- a/exercises/lists1/IntList.java +++ b/exercises/lists1/IntList.java @@ -9,17 +9,29 @@ public IntList(int f, IntList r) { /** Return the size of the list using... recursion! */ public int size() { - return 0; + if (rest == Null){ + return 1; + } + return 1+ this.rest.size(); } /** Return the size of the list using no recursion! */ public int iterativeSize() { - return 0; + int count = 0; + IntList p = this; + while (rest != Null){ + count += 1; + p = p.rest; + } + return count; } /** Returns the ith value in this list.*/ public int get(int i) { - return 0; + if (i == 0){ + return this.first; + } + return rest.get(i-1); } public static void main(String[] args) { @@ -29,4 +41,4 @@ public static void main(String[] args) { System.out.println(L.iterativeSize()); } -} \ No newline at end of file +}