diff --git a/.gitignore b/.gitignore
index 308d4d9..71cd997 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
Algodat.iml
+algodat.iml
target
\ No newline at end of file
diff --git a/algodat.iml b/algodat.iml
new file mode 100644
index 0000000..39e64ba
--- /dev/null
+++ b/algodat.iml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 940bd3b..af0be8a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,8 +13,8 @@
org.apache.maven.plugins
maven-compiler-plugin
-
- 10
+
+ 8
diff --git a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/ArrayList.java b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/ArrayList.java
index 6616db3..670df78 100644
--- a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/ArrayList.java
+++ b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/ArrayList.java
@@ -39,9 +39,19 @@ public class ArrayList implements List {
return size;
}
+ @Override
+ public E remove(int index) {
+ return null;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return false;
+ }
+
@NotNull
public Iterator iterator() {
- return new Iterator<>() {
+ return new Iterator() {
int next = 0;
int current;
diff --git a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/LinkedList.java b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/LinkedList.java
index 78bacb3..6f7def8 100644
--- a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/LinkedList.java
+++ b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/LinkedList.java
@@ -54,9 +54,37 @@ public class LinkedList implements List {
return size;
}
+ @Override
+ public E remove(int index) {
+ E e = get(index);
+ Wrapper run = this.first;
+ if(index >= size || index < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ size--;
+ if(index == 0) {
+ first = first.succ;
+ }else {
+ for (int i = 0; i < index - 1; i++) {
+ run = run.succ;
+ }
+ run.succ = run.succ.succ;
+
+ if(index == size) {
+ last = run;
+ }
+ }
+ return e;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return false;
+ }
+
@NotNull
public Iterator iterator() {
- return new Iterator<>() {
+ return new Iterator() {
Wrapper next = first;
Wrapper current;
diff --git a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/List.java b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/List.java
index c29a948..4038ce3 100644
--- a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/List.java
+++ b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/List.java
@@ -4,5 +4,7 @@ package xyz.joethei.studium.algodat.praktikum.blatt2;
public interface List extends Iterable{
boolean add(E e);
E get(int index);
- int size();
+ int size();
+ E remove(int index);
+ boolean remove(Object o);
}
diff --git a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java
index 2da7a51..5a63623 100644
--- a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java
+++ b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java
@@ -1,5 +1,7 @@
package xyz.joethei.studium.algodat.praktikum.blatt2;
+import java.util.Iterator;
+
public class Main {
public static void main(String[] args) {
@@ -22,10 +24,17 @@ public class Main {
}
System.out.println("\n");
+ aList.remove(5);
+
+ for (int i = 0; i < aList.size(); i++) {
+ System.out.print(aList.get(i) + " ");
+ }
+ System.out.println("\n");
+
List bList = new LinkedList<>();
for (int i = 1; i <= n; i++) {
- bList.add(i + "� = " + i * i);
+ bList.add(i + "^2 = " + i * i);
}
/* Ausgabe der String-LinkedList bList */
@@ -51,7 +60,7 @@ public class Main {
List dList = new ArrayList<>();
for (int i = 1; i <= n; i++) {
- dList.add(i + "� = " + i * i);
+ dList.add(i + "^2 = " + i * i);
}
/* Ausgabe der String-ArrayList dList */
@@ -61,5 +70,29 @@ public class Main {
}
System.out.println("\n");
+ List rList = new RingList<>();
+ for (int i = 1; i <= n; i++) {
+ rList.add(i * i);
+ }
+
+ /* Ausgabe der Integer-RingList rList */
+ System.out.println("--- Integer-RingList rList ---");
+ for (int i = 0; i < rList.size(); i++) {
+ System.out.print(rList.get(i) + " ");
+ }
+ System.out.println("\n");
+
+ for(int i : rList) {
+ System.out.print(i + " ");
+ }
+ System.out.println();
+
+ Iterator iter = rList.iterator();
+ while(iter.hasNext()) {
+ System.out.print(iter.next() + " ");
+ }
+ System.out.println();
+
+
}
}
diff --git a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/RingList.java b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/RingList.java
new file mode 100644
index 0000000..886685c
--- /dev/null
+++ b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/RingList.java
@@ -0,0 +1,88 @@
+package xyz.joethei.studium.algodat.praktikum.blatt2;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Iterator;
+
+public class RingList implements List {
+ private class Wrapper {
+ E e;
+ Wrapper succ;
+
+ Wrapper(E e) {
+ this.e = e;
+ succ = null;
+ }
+ }
+
+ private Wrapper first;
+ private Wrapper last;
+ private int size;
+
+ RingList() {
+ first = new Wrapper(null);
+ last = first;
+ last.succ = first;
+ size = 0;
+ }
+
+ public boolean add(E e) {
+ Wrapper w = new Wrapper(e);
+ last.succ = w;
+ last = w;
+ last.succ = first;
+ size++;
+ return true;
+ }
+
+ public E get(int index) {
+ Wrapper wRun;
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException();
+ }
+ wRun = this.first.succ;
+ for (int iRun = 0; iRun < index; iRun++) {
+ wRun = wRun.succ;
+ }
+ return wRun.e;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public E remove(int index) {
+ return null;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return false;
+ }
+
+ @NotNull
+ public Iterator iterator() {
+ return new Iterator() {
+ Wrapper next = first.succ;
+ Wrapper current;
+
+ public boolean hasNext() {
+ return next != first;
+ }
+
+ public E next() {
+ current = next;
+ if (next != first) {
+ next = next.succ;
+ }
+ return current.e;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+}
diff --git a/src/main/java/xyz/joethei/studium/algodat/DuplicatesList.java b/src/main/java/xyz/joethei/studium/algodat/vorlesung/DuplicatesList.java
similarity index 95%
rename from src/main/java/xyz/joethei/studium/algodat/DuplicatesList.java
rename to src/main/java/xyz/joethei/studium/algodat/vorlesung/DuplicatesList.java
index eb82d3d..b3445cf 100644
--- a/src/main/java/xyz/joethei/studium/algodat/DuplicatesList.java
+++ b/src/main/java/xyz/joethei/studium/algodat/vorlesung/DuplicatesList.java
@@ -1,4 +1,4 @@
-package xyz.joethei.studium.algodat;
+package xyz.joethei.studium.algodat.vorlesung;
import java.util.ArrayList;
import java.util.List;