Add 3 2 (Dynamic Size Queue)
This commit is contained in:
parent
f5319538ad
commit
233934e9b7
@ -10,6 +10,7 @@
|
|||||||
<br>Sowohl SourceCode, PDF als auch Word Datei
|
<br>Sowohl SourceCode, PDF als auch Word Datei
|
||||||
- VL 2 Aufgabe 1 (Erstellen von Testdaten)
|
- VL 2 Aufgabe 1 (Erstellen von Testdaten)
|
||||||
- VL 2 Aufgabe 2 (StringTokenizer)
|
- VL 2 Aufgabe 2 (StringTokenizer)
|
||||||
|
- VL 3 Aufgabe 2 (Dynamischer Speicher einer Queue)
|
||||||
- VL 3 Aufgabe 3 (ArrayList vs LinkedList)
|
- VL 3 Aufgabe 3 (ArrayList vs LinkedList)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,28 @@ package part3.aufg2;
|
|||||||
|
|
||||||
public class Anwendung {
|
public class Anwendung {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
|
Schlenglein kleinesSchlenglein = new Schlenglein();
|
||||||
|
|
||||||
|
System.out.println(kleinesSchlenglein.getArrayLenght());
|
||||||
|
|
||||||
|
for (int i=0; i<43; i++){
|
||||||
|
kleinesSchlenglein.add("a");
|
||||||
|
}
|
||||||
|
System.out.println(kleinesSchlenglein.getArrayLenght());
|
||||||
|
|
||||||
|
for (int i=0; i<35; i++){
|
||||||
|
kleinesSchlenglein.get();
|
||||||
|
}
|
||||||
|
System.out.println(kleinesSchlenglein.getArrayLenght());
|
||||||
|
|
||||||
|
for (int i=0; i<4321; i++){
|
||||||
|
kleinesSchlenglein.add("a");
|
||||||
|
}
|
||||||
|
System.out.println(kleinesSchlenglein.getArrayLenght());
|
||||||
|
|
||||||
|
for (int i=0; i<9999; i++){
|
||||||
|
kleinesSchlenglein.get();
|
||||||
|
}
|
||||||
|
System.out.println(kleinesSchlenglein.getArrayLenght());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public class Schlenglein <T>{
|
|||||||
public void add(T t){
|
public void add(T t){
|
||||||
this.myArray[this.numberOfElements] = t;
|
this.myArray[this.numberOfElements] = t;
|
||||||
this.numberOfElements++;
|
this.numberOfElements++;
|
||||||
|
attemptDynamicResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T get(){
|
public T get(){
|
||||||
@ -22,9 +23,36 @@ public class Schlenglein <T>{
|
|||||||
this.myArray[i] = this.myArray[i+1];
|
this.myArray[i] = this.myArray[i+1];
|
||||||
}
|
}
|
||||||
this.numberOfElements--;
|
this.numberOfElements--;
|
||||||
|
attemptDynamicResize();
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
public int size(){
|
public int size(){
|
||||||
return this.numberOfElements;
|
return this.numberOfElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getArrayLenght(){return this.maxSize;}
|
||||||
|
public void attemptDynamicResize(){
|
||||||
|
if (numberOfElements < 0.2*maxSize){
|
||||||
|
// Kleiner Machen
|
||||||
|
Object[] temp = new Object[maxSize];
|
||||||
|
|
||||||
|
System.arraycopy(myArray, 0, temp, 0, maxSize);
|
||||||
|
|
||||||
|
maxSize /= 2;
|
||||||
|
if (maxSize < 20){maxSize = 20;}
|
||||||
|
|
||||||
|
System.arraycopy(temp, 0, myArray, 0, maxSize);
|
||||||
|
|
||||||
|
} else if (numberOfElements > 0.8*maxSize) {
|
||||||
|
// Größer Machen
|
||||||
|
Object[] temp = new Object[maxSize];
|
||||||
|
|
||||||
|
System.arraycopy(myArray, 0, temp, 0, maxSize);
|
||||||
|
|
||||||
|
maxSize -=- maxSize;
|
||||||
|
myArray = new Object[maxSize];
|
||||||
|
|
||||||
|
System.arraycopy(temp, 0, myArray, 0, maxSize / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import java.util.LinkedList;
|
|||||||
* jeweils den Mittelwert!
|
* jeweils den Mittelwert!
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* Verwenden Sie für die Zeitmessung folgenden Code:
|
* Verwenden Sie für die Zeitmessung folgenden Code:
|
||||||
*
|
*
|
||||||
* long timeStart = System.currentTimeMillis();
|
* long timeStart = System.currentTimeMillis();
|
||||||
@ -58,7 +57,7 @@ public class Anwendung {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
int stringsToAdd = 50_000_000;
|
int stringsToAdd = 500_000;
|
||||||
long totalTimeSpent = 0;
|
long totalTimeSpent = 0;
|
||||||
int measurements = 10;
|
int measurements = 10;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user