From 2f4164a4e27d9c3e0d3e698eb8722e2009db170e Mon Sep 17 00:00:00 2001 From: a <@> Date: Tue, 12 Dec 2023 12:04:09 +0100 Subject: [PATCH] jbrg --- List.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/List.java b/List.java index efdfa67..ac48552 100644 --- a/List.java +++ b/List.java @@ -39,21 +39,29 @@ public class List } public void add(int n, T val) { + if(n >= size()) + { + add(val); + return; + } + if(n == 0) + { + neu.next = neu; + first = neu; + return; + } Node neu = new Node(); neu.wert = val; Node current = first; - if(first == null) - { - first = neu; - } else{ - while(current.next == null) + for(int i = 0; i < n -1;i++) { current = current.next; } + + neu.next = current.next; current.next = neu; - } } public boolean contains(T val) { @@ -68,6 +76,6 @@ public class List } public T remove(int n) { - + } }