Ü2: Anfang Implementation
This commit is contained in:
parent
88e27fad0f
commit
2fbe9d5f68
|
@ -1,2 +1,3 @@
|
|||
Algodat.iml
|
||||
algodat.iml
|
||||
target
|
|
@ -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>
|
4
pom.xml
4
pom.xml
|
@ -13,8 +13,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>10</source>
|
||||
<target>10</target>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -39,9 +39,19 @@ public class ArrayList<E> implements List<E> {
|
|||
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<>() {
|
||||
return new Iterator<E>() {
|
||||
int next = 0;
|
||||
int current;
|
||||
|
||||
|
|
|
@ -54,9 +54,37 @@ public class LinkedList<E> implements List<E> {
|
|||
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<E> iterator() {
|
||||
return new Iterator<>() {
|
||||
return new Iterator<E>() {
|
||||
Wrapper next = first;
|
||||
Wrapper current;
|
||||
|
||||
|
|
|
@ -4,5 +4,7 @@ package xyz.joethei.studium.algodat.praktikum.blatt2;
|
|||
public interface List<E> extends Iterable<E>{
|
||||
boolean add(E e);
|
||||
E get(int index);
|
||||
int size();
|
||||
int size();
|
||||
E remove(int index);
|
||||
boolean remove(Object o);
|
||||
}
|
||||
|
|
|
@ -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<String> bList = new LinkedList<>();
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
bList.add(i + "<EFBFBD> = " + i * i);
|
||||
bList.add(i + "^2 = " + i * i);
|
||||
}
|
||||
|
||||
/* Ausgabe der String-LinkedList bList */
|
||||
|
@ -51,7 +60,7 @@ public class Main {
|
|||
List<String> dList = new ArrayList<>();
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
dList.add(i + "<EFBFBD> = " + 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<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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.joethei.studium.algodat;
|
||||
package xyz.joethei.studium.algodat.vorlesung;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
Loading…
Reference in New Issue