Ubgrade 18.1. 2023
							parent
							
								
									f470c248c7
								
							
						
					
					
						commit
						90ff5d3a2a
					
				|  | @ -48,7 +48,7 @@ public class LinkedList<T> | |||
|         for(int i = 0; i<n; i++){ | ||||
|             current = current.next;    | ||||
|         } | ||||
|         return current.zahl; | ||||
|         return current.wert; | ||||
|     } | ||||
| 
 | ||||
|     public void loesche(int n){ | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ public class List<T> | |||
|         for(int i = 0; i<n; i++){ | ||||
|             current = current.next;    | ||||
|         } | ||||
|         return current.zahl; | ||||
|         return current.wert; | ||||
|     } | ||||
| 
 | ||||
|     public void loesche(int n){ | ||||
|  |  | |||
|  | @ -8,12 +8,12 @@ | |||
| public class Node<T> | ||||
| { | ||||
|      | ||||
| public T zahl; | ||||
| public T wert; | ||||
| 
 | ||||
| public Node<T> next; | ||||
| 
 | ||||
| public Node(T z){ | ||||
| zahl = z; | ||||
| wert = z; | ||||
| } | ||||
| public void setNext(Node n){ | ||||
| next = n; | ||||
|  |  | |||
|  | @ -0,0 +1,71 @@ | |||
| 
 | ||||
| /** | ||||
|  * Beschreiben Sie hier die Klasse Queue. | ||||
|  *  | ||||
|  * @author (Ihr Name)  | ||||
|  * @version (eine Versionsnummer oder ein Datum) | ||||
|  */ | ||||
| public class Queue<T> | ||||
| { | ||||
|      public Node<T> first; | ||||
|       | ||||
|     public Queue(){ | ||||
|     } | ||||
|     public boolean isEmpty(){ | ||||
|     if(first == null){ | ||||
|     return true; | ||||
|     } | ||||
|     return false; | ||||
|     } | ||||
|     public void enqueue (T neu) { | ||||
|         Node<T> n = new Node<T>(neu);//Neue Node mit Zahl "neu " anlegen
 | ||||
| 
 | ||||
|         //Überprüfe ob die liste leer ist
 | ||||
|         if(first == null){ | ||||
|             //setze neue node als erster Eintrag
 | ||||
|             first = n; | ||||
|         } | ||||
|         else { | ||||
|             Node<T> current = first; | ||||
| 
 | ||||
|             while(current.next != null){ | ||||
|                 current = current.next; | ||||
|             } | ||||
|             current.setNext(n); | ||||
|         } | ||||
| 
 | ||||
|         //current ist jetzt der letzte Eintrag
 | ||||
|         //setze neue Node als Nachfolger von bisher letztem Eintrag
 | ||||
|     } | ||||
| 
 | ||||
|     public int laenge(){ | ||||
|         Node current = first; | ||||
|         int laenge = 0; | ||||
|         while(current != null){ | ||||
|             current = current.next; | ||||
|             laenge++; | ||||
|         } | ||||
|         return laenge;    | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     public T dequeue(){ | ||||
|     if(first == null){ | ||||
|     return null; | ||||
|     } | ||||
|     else{ | ||||
|     Node<T> current = first; | ||||
|     first = first.next; | ||||
|     return current.wert; | ||||
|     } | ||||
|      | ||||
|     } | ||||
|     public T front(){ | ||||
|      | ||||
|     return first.wert; | ||||
|     } | ||||
|     } | ||||
| 
 | ||||
|     | ||||
| 
 | ||||
|  | @ -0,0 +1,68 @@ | |||
| 
 | ||||
| /** | ||||
|  * Beschreiben Sie hier die Klasse Stack. | ||||
|  *  | ||||
|  * @author (Ihr Name)  | ||||
|  * @version (eine Versionsnummer oder ein Datum) | ||||
|  */ | ||||
| public class Stack<T> | ||||
| { | ||||
|      public Node<T> first; | ||||
|       | ||||
|     public Stack(){ | ||||
|     } | ||||
|     public boolean isEmpty(){ | ||||
|     if(first == null){ | ||||
|     return true; | ||||
|     } | ||||
|     return false; | ||||
|     } | ||||
|     public void push (T neu) { | ||||
|         Node<T> n = new Node<T>(neu);//Neue Node mit Zahl "neu " anlegen
 | ||||
| 
 | ||||
|         //Überprüfe ob die liste leer ist
 | ||||
|         if(first == null){ | ||||
|             //setze neue node als erster Eintrag
 | ||||
|             first = n; | ||||
|         } | ||||
|         else { | ||||
|             Node<T> current = first; | ||||
| 
 | ||||
|             while(current.next != null){ | ||||
|                 current = current.next; | ||||
|             } | ||||
|             current.setNext(n); | ||||
|         } | ||||
| 
 | ||||
|         //current ist jetzt der letzte Eintrag
 | ||||
|         //setze neue Node als Nachfolger von bisher letztem Eintrag
 | ||||
|     } | ||||
| 
 | ||||
|     public int laenge(){ | ||||
|         Node current = first; | ||||
|         int laenge = 0; | ||||
|         while(current != null){ | ||||
|             current = current.next; | ||||
|             laenge++; | ||||
|         } | ||||
|         return laenge;    | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     public T pop(){ | ||||
|     if(first == null){ | ||||
|     return null; | ||||
|     } | ||||
|     else{ | ||||
|     Node<T> current = first; | ||||
|     first = first.next; | ||||
|     return current.wert; | ||||
|     } | ||||
|      | ||||
|     } | ||||
|     public T top(){ | ||||
|      | ||||
|     return first.wert; | ||||
|     } | ||||
|     } | ||||
							
								
								
									
										20
									
								
								test.java
								
								
								
								
							
							
						
						
									
										20
									
								
								test.java
								
								
								
								
							|  | @ -11,19 +11,31 @@ public class test | |||
|   Node<String> test = new Node<String>("Hallo"); | ||||
|   Node<Integer> test2 = new Node<Integer>(5); | ||||
|    | ||||
|  List liste = new List<String>(); | ||||
|  liste.einfuegen(5); | ||||
|  Queue<Integer> liste = new Queue<Integer>(); | ||||
|  /*liste.einfuegen(5); | ||||
|  liste.einfuegen(6); | ||||
|  liste.einfuegen(8); | ||||
|  liste.einfuegen(3); | ||||
|  liste.einfuegen(7); | ||||
|  liste.einfuegen(9); | ||||
|  liste.loesche(2); | ||||
|  liste.hinzufügen(4,"wirklich"); | ||||
|  liste.hinzufügen(4,"wirklich");*/ | ||||
|  liste.enqueue(7); | ||||
|  liste.enqueue(4); | ||||
|  liste.enqueue(8); | ||||
|  liste.enqueue(2); | ||||
|  liste.enqueue(0); | ||||
|  liste.enqueue(4); | ||||
|    int Selection = liste.dequeue(); | ||||
| System.out.println("Die  Zahl " +Selection+" wurde entfernt.");  | ||||
|    int Selection2 = liste.dequeue(); | ||||
| System.out.println("Die  Zahl " +Selection2+" wurde entfernt.");  | ||||
| int Angabe = liste.front(); | ||||
| System.out.println("Aktuell ist die erste Zahl " +Angabe+"."); | ||||
|   Node current = liste.first; | ||||
|    | ||||
|   while(current != null){ | ||||
|     System.out.println( current.zahl ); | ||||
|     System.out.println( current.wert ); | ||||
|     current = current.next; | ||||
|     } | ||||
|      | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue