Update 9.3.22
parent
08b40ec1d5
commit
c79bd06ca4
|
@ -4,20 +4,30 @@ public class AusführerSet {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Set<Integer> Set = new Set<Integer>();
|
Set<Integer> Set = new Set<Integer>();
|
||||||
|
Set<Integer> Set2 = new Set<Integer>();
|
||||||
|
|
||||||
Set.add(1);
|
Set.add(1);
|
||||||
Set.add(2);
|
|
||||||
Set.add(3);
|
Set.add(3);
|
||||||
Set.add(4);
|
|
||||||
Set.add(5);
|
Set.add(5);
|
||||||
Set.add(6);
|
Set.add(5);
|
||||||
|
Set.add(7);
|
||||||
|
Set.add(9);
|
||||||
|
|
||||||
|
Set2.add(2);
|
||||||
|
Set2.add(3);
|
||||||
|
Set2.add(4);
|
||||||
|
Set2.add(6);
|
||||||
|
Set2.add(9);
|
||||||
|
|
||||||
|
|
||||||
System.out.println(Set.contains(4));
|
System.out.println(Set.contains(4));
|
||||||
|
|
||||||
System.out.println(Set.isEmpty());
|
System.out.println(Set.isEmpty());
|
||||||
|
|
||||||
Set.remove(6);
|
Set.remove(7);
|
||||||
|
|
||||||
|
Set<Integer> I = Set.intersection (Set2);
|
||||||
|
I.Ausgabe();
|
||||||
|
|
||||||
System.out.println(Set.size());
|
System.out.println(Set.size());
|
||||||
|
|
||||||
|
|
|
@ -58,16 +58,41 @@ public class Set<X> {
|
||||||
Node<X> current = this.start;
|
Node<X> current = this.start;
|
||||||
if(current.wert == wert) {
|
if(current.wert == wert) {
|
||||||
this.start = current.next;
|
this.start = current.next;
|
||||||
|
size--;
|
||||||
}
|
}
|
||||||
while(current.next != null) {
|
while(current.next != null) {
|
||||||
if(current.next.wert == wert) {
|
if(current.next.wert == wert) {
|
||||||
current.next = current.next.next;
|
current.next = current.next.next;
|
||||||
size--;
|
size--;
|
||||||
|
} else {
|
||||||
|
current = current.next;
|
||||||
}
|
}
|
||||||
current = current.next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<X> intersection(Set<X> s) {
|
||||||
|
Set<X> result = new Set<X>();
|
||||||
|
Node<X> current = this.start;
|
||||||
|
while(current != null) {
|
||||||
|
if(s.contains(current.wert)) result.add(current.wert);
|
||||||
|
current = current.next;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public Set<X> union(Set<X> s) {
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
/*public Set<X> difference(Set<X> s) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<X> subset(Set<X> s) {
|
||||||
|
|
||||||
|
} */
|
||||||
|
|
||||||
public Node<X> getStart() {
|
public Node<X> getStart() {
|
||||||
return this.start;
|
return this.start;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +107,7 @@ public class Set<X> {
|
||||||
while(current != null) {
|
while(current != null) {
|
||||||
System.out.print(current.wert + " ");
|
System.out.print(current.wert + " ");
|
||||||
current = current.next;
|
current = current.next;
|
||||||
}
|
} System.out.print("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue