stack + queue
							parent
							
								
									55ebb889b5
								
							
						
					
					
						commit
						d3936993d3
					
				|  | @ -0,0 +1,52 @@ | |||
| 
 | ||||
| /** | ||||
|  * Beschreiben Sie hier die Klasse List_T_. | ||||
|  *  | ||||
|  * @author (Ihr Name)  | ||||
|  * @version (eine Versionsnummer oder ein Datum) | ||||
|  */ | ||||
| public class Stack<T> | ||||
| { | ||||
|     private Node<T> first; | ||||
|      | ||||
|     public Stack() { | ||||
|         first = null; | ||||
|     } | ||||
|      | ||||
|     public boolean isEmpty() { | ||||
|         if (first == null) return true; | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     public T top(int n) { | ||||
|         if (first == null) return null; | ||||
|         return first.wert; | ||||
|     } | ||||
|      | ||||
|     public void push(T val) { | ||||
|         Node<T> neu = new Node <T>(); | ||||
|         neu.wert = val; | ||||
|         neu.next = first; | ||||
|      | ||||
|         first = neu;  | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     public T pop(int n) { | ||||
|         if (first == null) return null; | ||||
|         T tmp = first.wert; // wert von first (=0) speichern
 | ||||
|         first = first.next; //first "pfeil" auf den nächsten
 | ||||
|         return tmp;//wert ausgeben
 | ||||
|     } | ||||
|      | ||||
|     public String toString(){ // glaub um halt alles schön auszugeben 
 | ||||
|         String result = ""; | ||||
|         Node<T> current = first; | ||||
|         while (current != null){ | ||||
|             result += current.wert + ", "; | ||||
|             current = current.next; | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
|     } | ||||
		Loading…
	
		Reference in New Issue