SOS wir haben eine contains Methode

master
SimonDHG 2023-12-11 17:22:14 +01:00
parent a4c2f13086
commit e2bf8c726e
1 changed files with 23 additions and 23 deletions

View File

@ -48,10 +48,16 @@ public class Set<T>
}
public void add (T val){
if (!this.contains(val)){
Node<T> added = new Node<T>(val);
if (this.first == null){
this.first = added;
this.last = added;
}
else{ this.last.next = added;
this.last = added;
}
}
}
public boolean contains (T val){
@ -64,31 +70,25 @@ public class Set<T>
}
public void remove(T val){
if(!this.contains(val))return;
Node<T> current = this.first;
int count = 0;
while (current != null){
if (current.next.wert == val){
this.remove(count);
}
count++;
while(current.next.wert != val){
current = current.next;
}
current.next.next = current.next;
}
private T remove(int n){
if (this.length <= n ) return null;
if ( n == 0) {
T ret = this.first.wert;
this.first = this.first.next;
this.length--;
return ret;
public Set<T> intersection(Set<T> s){
Set<T> tmp = new Set<T>();
Node<T> current = this.first;
while(current != null){
if (s.contains(current.wert)) tmp.add(current.wert);
current=current.next;
}
T ret = getNode(n).wert;
if (getNode(n-1).next.next == null) this.last = getNode(n-1);
getNode(n-1).next = getNode(n-1).next.next;
length--;
return ret;
return tmp;
}
/*public String toString(){
Node <T> current = this.first;
String tmp = "";