diff --git a/Programmierung2/src/LinkedList/Doubly/Double Linkedlist.pdf b/Programmierung2/src/LinkedList/Doubly/Double Linkedlist.pdf new file mode 100644 index 0000000..3e18785 Binary files /dev/null and b/Programmierung2/src/LinkedList/Doubly/Double Linkedlist.pdf differ diff --git a/Programmierung2/src/LinkedList/Doubly/ElementenList.java b/Programmierung2/src/LinkedList/Doubly/ElementenList.java new file mode 100644 index 0000000..8a38dc6 --- /dev/null +++ b/Programmierung2/src/LinkedList/Doubly/ElementenList.java @@ -0,0 +1,72 @@ +package LinkedList.Doubly; + +public class ElementenList { + Node head; + Node newNode; + public ElementenList(){ + newNode = new Node(); + } + + public void print() { + Node temp = head; + System.out.print("["); + while(temp != null) { + System.out.print(temp.value + " "); + temp = temp.next; + } + System.out.print("]"); + } + + // Add Methoden + public Node addLast(int value) { + Node newNode = new Node(); + newNode.value = value; + + if (head == null) { + head = newNode; + return newNode; + } + + Node temp = head; + while(temp.next != null) + temp = temp.next; + + temp.next = newNode; + newNode.prev = temp; + return newNode; + + } + public Node addFirst(int value) { + Node newNode = new Node(); + newNode.value = value; + + if (head == null) { + head = newNode; + return newNode; + } + newNode.next = head; + head = newNode; + return newNode; + + } + public Node addAtIndex(int value,int index) { + if (head == null) { + head = newNode; + return newNode; + } + if (index < 0) + return null; + + newNode.value = value; + Node temp = head; + for (int i = 0; i < index - 1 && temp.next != null; i++) + temp = temp.next; + + + newNode.next = temp.next; + newNode.prev = temp; + temp.next = newNode; + return newNode; + } + +} diff --git a/Programmierung2/src/LinkedList/Doubly/Node.java b/Programmierung2/src/LinkedList/Doubly/Node.java new file mode 100644 index 0000000..5dd9472 --- /dev/null +++ b/Programmierung2/src/LinkedList/Doubly/Node.java @@ -0,0 +1,8 @@ +package LinkedList.Doubly; + +public class Node { + int value; + Node next; + Node prev; + +} diff --git a/Programmierung2/src/LinkedList/Doubly/Test.java b/Programmierung2/src/LinkedList/Doubly/Test.java new file mode 100644 index 0000000..fc8c9f2 --- /dev/null +++ b/Programmierung2/src/LinkedList/Doubly/Test.java @@ -0,0 +1,24 @@ +package LinkedList.Doubly; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; + + +class Test { + private ElementenList list; + + @BeforeEach + public void list() { + + list = new ElementenList(); + } + + @org.junit.jupiter.api.Test + void testaddLast() { + Node temp = list.addLast(12); + temp = list.addLast(112); + assertEquals(112,11); + } + +} diff --git a/Programmierung2/src/Linked_List/ElementList.java b/Programmierung2/src/LinkedList/Single/ElementList.java similarity index 93% rename from Programmierung2/src/Linked_List/ElementList.java rename to Programmierung2/src/LinkedList/Single/ElementList.java index 04f0fde..95e8007 100644 --- a/Programmierung2/src/Linked_List/ElementList.java +++ b/Programmierung2/src/LinkedList/Single/ElementList.java @@ -1,4 +1,4 @@ -package Linked_List; +package LinkedList.Single; public class ElementList { Node head; diff --git a/Programmierung2/src/Linked_List/Node.java b/Programmierung2/src/LinkedList/Single/Node.java similarity index 58% rename from Programmierung2/src/Linked_List/Node.java rename to Programmierung2/src/LinkedList/Single/Node.java index d95e9b2..a341501 100644 --- a/Programmierung2/src/Linked_List/Node.java +++ b/Programmierung2/src/LinkedList/Single/Node.java @@ -1,4 +1,4 @@ -package Linked_List; +package LinkedList.Single; public class Node { int value; diff --git a/Programmierung2/src/LinkedList/Single/Single Linkedlist.pdf b/Programmierung2/src/LinkedList/Single/Single Linkedlist.pdf new file mode 100644 index 0000000..dd9b1f8 Binary files /dev/null and b/Programmierung2/src/LinkedList/Single/Single Linkedlist.pdf differ diff --git a/Programmierung2/src/Linked_List/Test.java b/Programmierung2/src/LinkedList/Single/Test.java similarity index 83% rename from Programmierung2/src/Linked_List/Test.java rename to Programmierung2/src/LinkedList/Single/Test.java index f78335e..4f4e58a 100644 --- a/Programmierung2/src/Linked_List/Test.java +++ b/Programmierung2/src/LinkedList/Single/Test.java @@ -1,4 +1,4 @@ -package Linked_List; +package LinkedList.Single; public class Test { diff --git a/Programmierung2/src/LinkedList/Single/Teste.java b/Programmierung2/src/LinkedList/Single/Teste.java new file mode 100644 index 0000000..d910cf7 --- /dev/null +++ b/Programmierung2/src/LinkedList/Single/Teste.java @@ -0,0 +1,18 @@ +package LinkedList.Single; + +import LinkedList.Doubly.ElementenList; + +public class Teste { + + public static void main(String[] args) { + ElementenList list = new ElementenList(); + list.addLast(5); + list.addLast(4); + list.addLast(3); + list.addAtIndex(10, 5); + + list.print(); + + } + +}