From b8b1658064d89d0580c86899c64a4e01620cf07a Mon Sep 17 00:00:00 2001 From: efan235 Date: Tue, 13 May 2025 23:23:56 -0700 Subject: [PATCH] Update IntList.java --- exercises/lists1/IntList.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 +}