13. Asar
							parent
							
								
									597945fb4a
								
							
						
					
					
						commit
						914ded100b
					
				|  | @ -0,0 +1,54 @@ | |||
| 
 | ||||
| public class LinkedList | ||||
| { | ||||
|   private Node start; | ||||
|   public LinkedList(){ | ||||
|        | ||||
|   } | ||||
|    | ||||
|   public void einfuegen(int zahl){ | ||||
|       Node neu = new Node(); | ||||
|          neu.wert = zahl; | ||||
|          if (this.start == null) { | ||||
|       this.start = neu; | ||||
|              Node current = this.start; | ||||
|       | ||||
|        | ||||
|       while (current.next != null) { | ||||
|           current = current.next; | ||||
|       } | ||||
|       current.next = neu; | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   public int laenge(){ | ||||
|       int count = 0; | ||||
|        | ||||
|       Node current = this.start; | ||||
|       while(current != null) { | ||||
|           current = current.next; | ||||
|           count++; | ||||
|       } | ||||
|       return count; | ||||
|   } | ||||
|   public String toString(){ | ||||
|       String result = " "; | ||||
|       Node current = this.start; | ||||
|       while( current != null) { | ||||
|           result += current.wert + ","; | ||||
|           current = current.next; | ||||
|       } | ||||
|       return result; | ||||
|   } | ||||
|    | ||||
|   public int erste(){ | ||||
|       int tmp = this.start.wert; | ||||
|       this.start = this.start.next; | ||||
|       return tmp; | ||||
|   } | ||||
|    | ||||
|   public int getNteZahl(int n){ | ||||
|       return 0; | ||||
|   } | ||||
|    | ||||
| } | ||||
|  | @ -0,0 +1,13 @@ | |||
| 
 | ||||
| public class Node | ||||
| { | ||||
|   public int wert; | ||||
|   public Node next; | ||||
|    | ||||
|   public void setWert(int w){ | ||||
|       this.wert = w; | ||||
|   } | ||||
|   public void setNext(Node n){ | ||||
|       this.next = n; | ||||
|   } | ||||
| } | ||||
|  | @ -0,0 +1,22 @@ | |||
| 
 | ||||
| public class Test2 | ||||
| { | ||||
|   public static  Node test() { | ||||
|       Node n1 = new Node(); | ||||
|       n1.setWert(3); | ||||
|        | ||||
|       Node n2 = new Node(); | ||||
|       n2.setWert(7); | ||||
|       n1.setNext(n2); | ||||
|        | ||||
|       Node n3 = new Node(); | ||||
|       n3.setWert(11); | ||||
|       n2.setNext(n3); | ||||
|        | ||||
|       Node n4 = new Node(); | ||||
|       n4.setWert(12);n3.setNext(n4); | ||||
|        | ||||
|       return n1; | ||||
|   } | ||||
|     } | ||||
| 
 | ||||
|  | @ -0,0 +1,19 @@ | |||
| 
 | ||||
| public class Test3 | ||||
| { | ||||
|     public static void test(){ | ||||
|         LinkedList l = new LinkedList(); | ||||
|          | ||||
|         l.einfuegen(4); | ||||
|         l.einfuegen(8); | ||||
|         l.einfuegen(3); | ||||
|         l.einfuegen(17); | ||||
|          | ||||
|         System.out.println(l); | ||||
|         System.out.println(l.erste() ); | ||||
|          | ||||
|          | ||||
|         System.out.println(1); | ||||
|          | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue