diff --git a/README.md b/README.md index 11873e0..1c54c66 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@
Sowohl SourceCode, PDF als auch Word Datei - VL 2 Aufgabe 1 (Erstellen von Testdaten) - VL 2 Aufgabe 2 (StringTokenizer) +- VL 3 Aufgabe 3 (ArrayList vs LinkedList) - keine diff --git a/src/part3/aufg3/Anwendung.java b/src/part3/aufg3/Anwendung.java index a648669..959a6e0 100644 --- a/src/part3/aufg3/Anwendung.java +++ b/src/part3/aufg3/Anwendung.java @@ -1,5 +1,8 @@ package part3.aufg3; +import java.util.ArrayList; +import java.util.LinkedList; + /** * Aufgabe 3 * Es soll die Einfügeperformance der beiden Klassen LinkedList und ArrayList verglichen @@ -23,24 +26,76 @@ package part3.aufg3; public class Anwendung { - private String getRandomString(){ + public static String getRandomString(int MIN_LENGTH, int MAX_LENGTH) { char[] alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; int size; - do{ - size = (int) Math.random()*16; - }while (size<10); + do { + size = (int) (Math.random() * MAX_LENGTH); + } while (size < MIN_LENGTH); String output = ""; int index; - for (int i=0; i ls, int amount) { + for (int i = 0; i < amount; i++) { + ls.add(getRandomString(10, 16)); + } + } + + public static void fillWithRandomStrings(ArrayList ls, int amount){ + for (int i=0; i ls = new LinkedList<>(); + ArrayList ls = new ArrayList<>(); + + fillWithRandomStrings(ls, stringsToAdd); + + long timeEnd = System.currentTimeMillis(); + long timeSpent = timeEnd-timeStart; + totalTimeSpent += timeSpent; + + System.out.println(timeSpent); + } + System.out.println("Average of " + measurements + ": " + (totalTimeSpent/measurements)); } } + +/* + Linked List: ArrayLis: + 10k 10 single Time of 0 ??? 7 + 20k 9 Here too ?? 11 + 50k 24 22 + + 100k 47 37 + 200k 99 74 + 500k 245 188 + + 1Mil 737 350 + 2Mil 1576 688 + 5Mil 4173 1650 + + 10Mil 8600 3300 + 20Mil 17750 6690 + 50Mil 43600 24860 + */ \ No newline at end of file