vl 13 afg 1,2,3 gepusht
This commit is contained in:
parent
24c775587e
commit
41379aafe3
BIN
Vl13 Afg1.zip
BIN
Vl13 Afg1.zip
Binary file not shown.
2
Vl13 Afg1/.idea/misc.xml
generated
2
Vl13 Afg1/.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
29
Vl13 Afg2/.gitignore
vendored
Normal file
29
Vl13 Afg2/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
8
Vl13 Afg2/.idea/.gitignore
generated
vendored
Normal file
8
Vl13 Afg2/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
Vl13 Afg2/.idea/misc.xml
generated
Normal file
6
Vl13 Afg2/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
Vl13 Afg2/.idea/modules.xml
generated
Normal file
8
Vl13 Afg2/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Vl13 Afg2.iml" filepath="$PROJECT_DIR$/Vl13 Afg2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
Vl13 Afg2/Vl13 Afg2.iml
Normal file
11
Vl13 Afg2/Vl13 Afg2.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
35
Vl13 Afg2/src/Anwendung.java
Normal file
35
Vl13 Afg2/src/Anwendung.java
Normal file
@ -0,0 +1,35 @@
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class Anwendung {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Erstellen einer Instanz der MyQueue-Klasse
|
||||
MyQueue<Integer> queue = new MyQueue<>();
|
||||
|
||||
// Hinzufügen von Elementen zur Warteschlange
|
||||
for (int i = 1; i <= 25; i++) {
|
||||
queue.add(i);
|
||||
System.out.println("Added: " + i);
|
||||
}
|
||||
|
||||
// Ausgabe der Anzahl der Elemente in der Warteschlange
|
||||
System.out.println("Queue size: " + queue.size());
|
||||
// Überprüfen der Feldgröße nach dem Befpllen
|
||||
System.out.println("Queue array size after filling: " + queue.getArraySize());
|
||||
|
||||
// Entfernen und Ausgabe der Elemente aus der Warteschlange
|
||||
try {
|
||||
while (queue.size() > 0) {
|
||||
System.out.println("Removed: " + queue.get());
|
||||
}
|
||||
} catch (NoSuchElementException e) {
|
||||
System.out.println("Queue is empty");
|
||||
}
|
||||
|
||||
// Überprüfen der Größe nach dem Entleeren
|
||||
System.out.println("Queue size after emptying: " + queue.size());
|
||||
|
||||
// Überprüfen der Feldgröße nach dem Entleeren
|
||||
System.out.println("Queue array size after emptying: " + queue.getArraySize());
|
||||
}
|
||||
}
|
57
Vl13 Afg2/src/MyQueue.java
Normal file
57
Vl13 Afg2/src/MyQueue.java
Normal file
@ -0,0 +1,57 @@
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class MyQueue<T> {
|
||||
|
||||
private Object[] myArray;
|
||||
private int numberOfElements;
|
||||
private int maxSize;
|
||||
|
||||
public MyQueue() {
|
||||
this.numberOfElements = 0;
|
||||
this.maxSize = 20; // Startfeldgröße
|
||||
myArray = new Object[this.maxSize];
|
||||
}
|
||||
|
||||
public void add(T t) {
|
||||
// Überprüfen, ob die Feldgröße angepasst werden muss
|
||||
if (((double) numberOfElements / maxSize) >= 0.8) {
|
||||
resizeArray(maxSize * 2); // Verdopple die Feldgröße
|
||||
}
|
||||
// Element hinzufügen
|
||||
myArray[numberOfElements++] = t;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if (numberOfElements == 0) {
|
||||
throw new NoSuchElementException("Queue is empty");
|
||||
}
|
||||
T retValue = (T) myArray[0];
|
||||
// Verschiebe die Elemente um eine Position nach links
|
||||
for (int i = 0; i < numberOfElements - 1; i++) {
|
||||
myArray[i] = myArray[i + 1];
|
||||
}
|
||||
numberOfElements--;
|
||||
// Überprüfen, ob die Feldgröße angepasst werden muss
|
||||
if (((double) numberOfElements / maxSize) <= 0.2 && maxSize > 20) {
|
||||
resizeArray(maxSize / 2); // Halbiere die Feldgröße
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return numberOfElements;
|
||||
}
|
||||
|
||||
// Methode zum Anpassen der Feldgröße
|
||||
private void resizeArray(int newSize) {
|
||||
Object[] newArray = new Object[newSize];
|
||||
// Kopiere vorhandene Elemente in das neue Array
|
||||
System.arraycopy(myArray, 0, newArray, 0, numberOfElements);
|
||||
myArray = newArray;
|
||||
maxSize = newSize;
|
||||
}
|
||||
|
||||
public int getArraySize() {
|
||||
return maxSize;
|
||||
}
|
||||
}
|
29
Vl13 Afg3/.gitignore
vendored
Normal file
29
Vl13 Afg3/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
8
Vl13 Afg3/.idea/.gitignore
generated
vendored
Normal file
8
Vl13 Afg3/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
Vl13 Afg3/.idea/misc.xml
generated
Normal file
6
Vl13 Afg3/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
Vl13 Afg3/.idea/modules.xml
generated
Normal file
8
Vl13 Afg3/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Vl13 Afg3.iml" filepath="$PROJECT_DIR$/Vl13 Afg3.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
Vl13 Afg3/Vl13 Afg3.iml
Normal file
11
Vl13 Afg3/Vl13 Afg3.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
BIN
Vl13 Afg3/große Zahl go brrrrr.png
Normal file
BIN
Vl13 Afg3/große Zahl go brrrrr.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 325 KiB |
48
Vl13 Afg3/results.txt
Normal file
48
Vl13 Afg3/results.txt
Normal file
@ -0,0 +1,48 @@
|
||||
Size: 10000
|
||||
ArrayList Average Time (ms): 2.5
|
||||
LinkedList Average Time (ms): 1.6
|
||||
|
||||
Size: 20000
|
||||
ArrayList Average Time (ms): 2.7
|
||||
LinkedList Average Time (ms): 2.6
|
||||
|
||||
Size: 50000
|
||||
ArrayList Average Time (ms): 6.6
|
||||
LinkedList Average Time (ms): 7.8
|
||||
|
||||
Size: 100000
|
||||
ArrayList Average Time (ms): 15.4
|
||||
LinkedList Average Time (ms): 11.5
|
||||
|
||||
Size: 200000
|
||||
ArrayList Average Time (ms): 21.2
|
||||
LinkedList Average Time (ms): 23.6
|
||||
|
||||
Size: 500000
|
||||
ArrayList Average Time (ms): 54.3
|
||||
LinkedList Average Time (ms): 62.8
|
||||
|
||||
Size: 1000000
|
||||
ArrayList Average Time (ms): 163.2
|
||||
LinkedList Average Time (ms): 118.7
|
||||
|
||||
Size: 2000000
|
||||
ArrayList Average Time (ms): 278.6
|
||||
LinkedList Average Time (ms): 237.5
|
||||
|
||||
Size: 5000000
|
||||
ArrayList Average Time (ms): 622.1
|
||||
LinkedList Average Time (ms): 1380.0
|
||||
|
||||
Size: 10000000
|
||||
ArrayList Average Time (ms): 1305.3
|
||||
LinkedList Average Time (ms): 3043.1
|
||||
|
||||
Size: 20000000
|
||||
ArrayList Average Time (ms): 2638.0
|
||||
LinkedList Average Time (ms): 6286.8
|
||||
|
||||
Size: 50000000
|
||||
ArrayList Average Time (ms): 6578.2
|
||||
LinkedList Average Time (ms): 15891.3
|
||||
|
59
Vl13 Afg3/src/Anwendung.java
Normal file
59
Vl13 Afg3/src/Anwendung.java
Normal file
@ -0,0 +1,59 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Anwendung {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] sizes = {10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000, 5000000, 10000000, 20000000, 50000000};
|
||||
|
||||
StringBuilder resultBuilder = new StringBuilder();
|
||||
|
||||
for (int size : sizes) {
|
||||
List<String> randomStrings = new ArrayList<>(size); // ArrayList für Vergleich
|
||||
long arrayListTotalTime = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
long arrayListTimeStart = System.currentTimeMillis();
|
||||
for (int j = 0; j < size; j++) {
|
||||
randomStrings.add(RString.randomStringGenerator());
|
||||
}
|
||||
long arrayListTimeEnd = System.currentTimeMillis();
|
||||
long arrayListElapsedTime = arrayListTimeEnd - arrayListTimeStart;
|
||||
arrayListTotalTime += arrayListElapsedTime;
|
||||
randomStrings.clear();
|
||||
}
|
||||
double arrayListAverageTime = (double) arrayListTotalTime / 10;
|
||||
|
||||
randomStrings = new LinkedList<>(); // LinkedList für Vergleich
|
||||
long linkedListTotalTime = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
long linkedListTimeStart = System.currentTimeMillis();
|
||||
for (int j = 0; j < size; j++) {
|
||||
randomStrings.add(RString.randomStringGenerator());
|
||||
}
|
||||
long linkedListTimeEnd = System.currentTimeMillis();
|
||||
long linkedListElapsedTime = linkedListTimeEnd - linkedListTimeStart;
|
||||
linkedListTotalTime += linkedListElapsedTime;
|
||||
randomStrings.clear();
|
||||
}
|
||||
double linkedListAverageTime = (double) linkedListTotalTime / 10;
|
||||
|
||||
// Ergebnisse auf der Konsole ausgeben
|
||||
System.out.println("Size: " + size);
|
||||
System.out.println("ArrayList Average Time (ms): " + arrayListAverageTime);
|
||||
System.out.println("LinkedList Average Time (ms): " + linkedListAverageTime);
|
||||
System.out.println();
|
||||
|
||||
// Ergebnisse zu einem String hinzufügen
|
||||
resultBuilder.append("Size: ").append(size).append("\n");
|
||||
resultBuilder.append("ArrayList Average Time (ms): ").append(arrayListAverageTime).append("\n");
|
||||
resultBuilder.append("LinkedList Average Time (ms): ").append(linkedListAverageTime).append("\n");
|
||||
resultBuilder.append("\n");
|
||||
}
|
||||
|
||||
// Ergebnisse in eine Datei schreiben
|
||||
ResultWriter.writeResultsToFile("results.txt", resultBuilder.toString());
|
||||
}
|
||||
}
|
22
Vl13 Afg3/src/RString.java
Normal file
22
Vl13 Afg3/src/RString.java
Normal file
@ -0,0 +1,22 @@
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class RString {
|
||||
|
||||
//Zeichensatz für Stringgenerator
|
||||
private static final String ZEICHEN = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWQYZ1234567890";
|
||||
|
||||
//Methode zur Generierung von rnadom Strings zwischen 10 und 16 Zeichen
|
||||
public static String randomStringGenerator(){
|
||||
Random random = new Random();
|
||||
int length = random.nextInt(7) + 10;
|
||||
StringBuilder stringBuilder = new StringBuilder(length);
|
||||
for(int i = 0; i < length; i++){
|
||||
int randomIndex = random.nextInt(ZEICHEN.length());
|
||||
stringBuilder.append(ZEICHEN.charAt(randomIndex));
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
14
Vl13 Afg3/src/ResultWriter.java
Normal file
14
Vl13 Afg3/src/ResultWriter.java
Normal file
@ -0,0 +1,14 @@
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ResultWriter {
|
||||
|
||||
public static void writeResultsToFile(String filename, String results) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
writer.write(results);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user