From c79bd06ca4591ef382f1faf904eace65749eb691 Mon Sep 17 00:00:00 2001 From: mittelni Date: Wed, 9 Mar 2022 11:05:37 +0100 Subject: [PATCH] Update 9.3.22 --- List-Queue-Stack-Set/src/AusführerSet.java | 18 +++++++++++--- List-Queue-Stack-Set/src/Set.java | 29 ++++++++++++++++++++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/List-Queue-Stack-Set/src/AusführerSet.java b/List-Queue-Stack-Set/src/AusführerSet.java index 2da8fbb..6a39a40 100755 --- a/List-Queue-Stack-Set/src/AusführerSet.java +++ b/List-Queue-Stack-Set/src/AusführerSet.java @@ -4,20 +4,30 @@ public class AusführerSet { public static void main(String[] args) { Set Set = new Set(); + Set Set2 = new Set(); Set.add(1); - Set.add(2); Set.add(3); - Set.add(4); 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.isEmpty()); - Set.remove(6); + Set.remove(7); + + Set I = Set.intersection (Set2); + I.Ausgabe(); System.out.println(Set.size()); diff --git a/List-Queue-Stack-Set/src/Set.java b/List-Queue-Stack-Set/src/Set.java index 4fa601e..d4ebbf2 100755 --- a/List-Queue-Stack-Set/src/Set.java +++ b/List-Queue-Stack-Set/src/Set.java @@ -58,16 +58,41 @@ public class Set { Node current = this.start; if(current.wert == wert) { this.start = current.next; + size--; } while(current.next != null) { if(current.next.wert == wert) { current.next = current.next.next; size--; + } else { + current = current.next; } - current = current.next; + } } + public Set intersection(Set s) { + Set result = new Set(); + Node current = this.start; + while(current != null) { + if(s.contains(current.wert)) result.add(current.wert); + current = current.next; + } + return result; + } + + //public Set union(Set s) { + + //} + + /*public Set difference(Set s) { + + } + + public Set subset(Set s) { + + } */ + public Node getStart() { return this.start; } @@ -82,7 +107,7 @@ public class Set { while(current != null) { System.out.print(current.wert + " "); current = current.next; - } + } System.out.print("\n"); } }