diff --git a/List-Queue-Stack-Set/src/AusführerSet.java b/List-Queue-Stack-Set/src/AusführerSet.java index 6847c55..9296545 100755 --- a/List-Queue-Stack-Set/src/AusführerSet.java +++ b/List-Queue-Stack-Set/src/AusführerSet.java @@ -1,4 +1,26 @@ public class AusführerSet { + + public static void main(String[] args) { + + Set Set = new Set(); + + Set.add(1); + Set.add(2); + Set.add(3); + Set.add(4); + Set.add(5); + Set.add(6); + + + System.out.println(Set.contains(4)); + + System.out.println(Set.isEmpty()); + + System.out.println(Set.size()); + + Set.Ausgabe(); + + } } diff --git a/List-Queue-Stack-Set/src/Set.java b/List-Queue-Stack-Set/src/Set.java index f18e3e7..6b737a8 100755 --- a/List-Queue-Stack-Set/src/Set.java +++ b/List-Queue-Stack-Set/src/Set.java @@ -1,4 +1,74 @@ -public class Set { +public class Set { + private Node start; + + private int size; + + public Set() { + this.start = null; + this.size = 0; + } + + public boolean isEmpty() { + if(size == 0) { + return true; + } else { + return false; + } + } + + public boolean contains(X wert) { + + Node current = this.start; + while(current != null) { + + if(current.wert == wert) { + return true; + } + current = current.next; + + } + return false; + + } + + public void add(X wert) { + if(contains(wert) == false) { + this.size++; + + if(this.start == null) { + this.start = new Node(wert); + } else { + Node current = this.start; + while (current.next != null) { + current = current.next; + + } + current.next = new Node(wert); + } + + } else { + return; + } + + } + + public Node getStart() { + return this.start; + } + + public int size() { + return this.size; + } + + public void Ausgabe() { + Node current = this.start; + + while(current != null) { + System.out.print(current.wert + " "); + current = current.next; + } + } + }