Ü2: Anfang Implementation

This commit is contained in:
Johannes Theiner 2018-11-13 13:23:15 +01:00
parent 88e27fad0f
commit 2fbe9d5f68
9 changed files with 191 additions and 8 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
Algodat.iml Algodat.iml
algodat.iml
target target

21
algodat.iml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.3.1" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
</component>
</module>

View File

@ -13,8 +13,8 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>10</source> <source>8</source>
<target>10</target> <target>8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -39,9 +39,19 @@ public class ArrayList<E> implements List<E> {
return size; return size;
} }
@Override
public E remove(int index) {
return null;
}
@Override
public boolean remove(Object o) {
return false;
}
@NotNull @NotNull
public Iterator<E> iterator() { public Iterator<E> iterator() {
return new Iterator<>() { return new Iterator<E>() {
int next = 0; int next = 0;
int current; int current;

View File

@ -54,9 +54,37 @@ public class LinkedList<E> implements List<E> {
return size; 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 @NotNull
public Iterator<E> iterator() { public Iterator<E> iterator() {
return new Iterator<>() { return new Iterator<E>() {
Wrapper next = first; Wrapper next = first;
Wrapper current; Wrapper current;

View File

@ -4,5 +4,7 @@ package xyz.joethei.studium.algodat.praktikum.blatt2;
public interface List<E> extends Iterable<E>{ public interface List<E> extends Iterable<E>{
boolean add(E e); boolean add(E e);
E get(int index); E get(int index);
int size(); int size();
E remove(int index);
boolean remove(Object o);
} }

View File

@ -1,5 +1,7 @@
package xyz.joethei.studium.algodat.praktikum.blatt2; package xyz.joethei.studium.algodat.praktikum.blatt2;
import java.util.Iterator;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
@ -22,10 +24,17 @@ public class Main {
} }
System.out.println("\n"); 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<String> bList = new LinkedList<>(); List<String> bList = new LinkedList<>();
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
bList.add(i + "<EFBFBD> = " + i * i); bList.add(i + "^2 = " + i * i);
} }
/* Ausgabe der String-LinkedList bList */ /* Ausgabe der String-LinkedList bList */
@ -51,7 +60,7 @@ public class Main {
List<String> dList = new ArrayList<>(); List<String> dList = new ArrayList<>();
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
dList.add(i + "<EFBFBD> = " + i * i); dList.add(i + "^2 = " + i * i);
} }
/* Ausgabe der String-ArrayList dList */ /* Ausgabe der String-ArrayList dList */
@ -61,5 +70,29 @@ public class Main {
} }
System.out.println("\n"); System.out.println("\n");
List<Integer> 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<Integer> iter = rList.iterator();
while(iter.hasNext()) {
System.out.print(iter.next() + " ");
}
System.out.println();
} }
} }

View File

@ -0,0 +1,88 @@
package xyz.joethei.studium.algodat.praktikum.blatt2;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
public class RingList<E> implements List<E> {
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<E> iterator() {
return new Iterator<E>() {
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();
}
};
}
}

View File

@ -1,4 +1,4 @@
package xyz.joethei.studium.algodat; package xyz.joethei.studium.algodat.vorlesung;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;