jbrg
parent
647b940584
commit
2f4164a4e2
20
List.java
20
List.java
|
@ -39,22 +39,30 @@ public class List<T>
|
|||
}
|
||||
public void add(int n, T val)
|
||||
{
|
||||
if(n >= size())
|
||||
{
|
||||
add(val);
|
||||
return;
|
||||
}
|
||||
if(n == 0)
|
||||
{
|
||||
neu.next = neu;
|
||||
first = neu;
|
||||
return;
|
||||
}
|
||||
Node<T> neu = new Node<T>();
|
||||
neu.wert = val;
|
||||
|
||||
Node<T> 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)
|
||||
{
|
||||
Node<T> current = first;
|
||||
|
|
Loading…
Reference in New Issue