update1
							parent
							
								
									e5a182a57f
								
							
						
					
					
						commit
						1c3c13fdef
					
				|  | @ -1,4 +1,26 @@ | |||
| 
 | ||||
| public class AusführerSet { | ||||
| 	 | ||||
| 	public static void main(String[] args) { | ||||
| 		 | ||||
| 		Set<Integer> Set = new Set<Integer>(); | ||||
| 		 | ||||
| 		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(); | ||||
| 		 | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -1,4 +1,74 @@ | |||
| 
 | ||||
| public class Set { | ||||
| public class Set<X> { | ||||
| 
 | ||||
| 	private Node<X> 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<X> 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<X>(wert);			 | ||||
| 			} else {  | ||||
| 				Node<X> current = this.start;		 | ||||
| 				while (current.next != null) {				 | ||||
| 					current = current.next;	 | ||||
| 	 | ||||
| 				} | ||||
| 				current.next = new Node<X>(wert); | ||||
| 			} | ||||
| 			 | ||||
| 		} else { | ||||
| 			return; | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	public Node<X> getStart() {  | ||||
| 		return this.start;		 | ||||
| 	} | ||||
| 	 | ||||
| 	public int size() {	 | ||||
| 		return this.size;	 | ||||
| 	} | ||||
| 	 | ||||
| 	public void Ausgabe() { | ||||
| 		Node<X> current = this.start;	 | ||||
| 				 | ||||
| 			while(current != null) {	 | ||||
| 				System.out.print(current.wert + " ");	 | ||||
| 				current = current.next;	 | ||||
| 			} | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue