master
			
			
		
		
							parent
							
								
									e4e0712be5
								
							
						
					
					
						commit
						fe6626297f
					
				
							
								
								
									
										34
									
								
								List.java
								
								
								
								
							
							
						
						
									
										34
									
								
								List.java
								
								
								
								
							|  | @ -1,13 +1,29 @@ | ||||||
| public class List<T> | public class List<T> | ||||||
| { | { | ||||||
|  |     /** | ||||||
|  |      * erster Eintrag der Liste | ||||||
|  |      */ | ||||||
|     public Node<T> first; |     public Node<T> first; | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Konstruktor | ||||||
|  |      */ | ||||||
|     public List() {} |     public List() {} | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Überprüft, ob die Liste leer ist | ||||||
|  |      *  | ||||||
|  |      * @return true, wenn keine Elemente in der Liste | ||||||
|  |      */ | ||||||
|     public boolean isEmpty() { |     public boolean isEmpty() { | ||||||
|         return first == null; |         return first == null; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Berechnet die Größe der Liste | ||||||
|  |      *  | ||||||
|  |      * @return Anzahl der Elemente in der Liste | ||||||
|  |      */ | ||||||
|     public int size() { |     public int size() { | ||||||
|         Node<T> current = first; |         Node<T> current = first; | ||||||
|         int laenge = 0; |         int laenge = 0; | ||||||
|  | @ -20,6 +36,10 @@ public class List<T> | ||||||
|         return laenge; |         return laenge; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Gibt das Element an der n-ten Stelle zurück, oder null | ||||||
|  |      * falls die Liste kürzer ist | ||||||
|  |      */ | ||||||
|     public T get(int n) { |     public T get(int n) { | ||||||
|         Node<T> current = first; |         Node<T> current = first; | ||||||
|          |          | ||||||
|  | @ -32,6 +52,9 @@ public class List<T> | ||||||
|         return current.wert; |         return current.wert; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Fügt ein neues Element am Ende der Liste ein | ||||||
|  |      */ | ||||||
|     public void add(T neu) { |     public void add(T neu) { | ||||||
|         Node n = new Node<T>(neu); // Neue Node mit Zahl "neu" anlegen
 |         Node n = new Node<T>(neu); // Neue Node mit Zahl "neu" anlegen
 | ||||||
|          |          | ||||||
|  | @ -53,6 +76,10 @@ public class List<T> | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Fügt ein neues Element an der Stelle n in die Liste ein | ||||||
|  |      * oder am Ende, falls die Liste kürzer ist. | ||||||
|  |      */ | ||||||
|     public void add(int n, T wert) { |     public void add(int n, T wert) { | ||||||
|         // Neue Node anlegen
 |         // Neue Node anlegen
 | ||||||
|         Node<T> neu = new Node<T>(wert); |         Node<T> neu = new Node<T>(wert); | ||||||
|  | @ -79,6 +106,9 @@ public class List<T> | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Überprüft, ob die Liste einen konkreten Wert enthält | ||||||
|  |      */ | ||||||
|     public boolean contains(T wert) { |     public boolean contains(T wert) { | ||||||
|         Node<T> current = first; |         Node<T> current = first; | ||||||
|          |          | ||||||
|  | @ -91,6 +121,10 @@ public class List<T> | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * Löscht das Element an der Stelle n und gibt | ||||||
|  |      * dessen Wert zurück | ||||||
|  |      */ | ||||||
|     public T remove(int n) { |     public T remove(int n) { | ||||||
|         if (n >= size()) return null; |         if (n >= size()) return null; | ||||||
|          |          | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue