Cleanup VL 3
This commit is contained in:
parent
a812a10736
commit
438fdeef0c
@ -1,17 +1,16 @@
|
||||
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
|
||||
// then press Enter. You can now see whitespace characters in your code.
|
||||
|
||||
import part3.aufg3.Anwendung;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// Press Alt+Eingabe with your caret at the highlighted text to see how
|
||||
// IntelliJ IDEA suggests fixing it.
|
||||
System.out.println("Hello and welcome!");
|
||||
int size;
|
||||
int MAX_LENGTH = 3;
|
||||
int MIN_LENGTH = 10;
|
||||
|
||||
// Press Umschalt+F10 or click the green arrow button in the gutter to run the code.
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
|
||||
// Press Umschalt+F9 to start debugging your code. We have set one breakpoint
|
||||
// for you, but you can always add more by pressing Strg+F8.
|
||||
System.out.println("i = " + i);
|
||||
for (int i = 0; i <25; i++) {
|
||||
size = (int) (Math.random() * MAX_LENGTH);
|
||||
System.out.println(size);
|
||||
}
|
||||
}
|
||||
}
|
@ -45,10 +45,11 @@ public class Anwendung {
|
||||
|
||||
myStack.print();
|
||||
myStack.p_push(1);
|
||||
myStack.p_push('B');
|
||||
myStack.p_push('J');
|
||||
myStack.p_push(true);
|
||||
|
||||
myStack.p_pop();
|
||||
|
||||
myStack.p_push("\"Ich Liebe Generische Typen\"");
|
||||
}
|
||||
|
||||
|
@ -34,10 +34,11 @@ public class GenericStack<T> {
|
||||
}
|
||||
|
||||
public Object[] toArray(){
|
||||
Object[] retArray = new Object[this.firstFreeIndex];
|
||||
|
||||
if (this.firstFreeIndex<1){
|
||||
return new Object[0];
|
||||
}
|
||||
Object[] retArray = new Object[this.firstFreeIndex];
|
||||
for (int i=0; i<firstFreeIndex; i++){
|
||||
retArray[i] = this.myArray[i];
|
||||
}
|
||||
@ -47,5 +48,4 @@ public class GenericStack<T> {
|
||||
public void print(){
|
||||
System.out.println(Arrays.toString(this.toArray()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -34,10 +34,11 @@ public class IntStack {
|
||||
}
|
||||
|
||||
public int[] toArray(){
|
||||
int[] retArray = new int[firstFreeIndex];
|
||||
|
||||
if (firstFreeIndex<1){
|
||||
return new int[0];
|
||||
}
|
||||
int[] retArray = new int[firstFreeIndex];
|
||||
for (int i=0; i<firstFreeIndex; i++){
|
||||
retArray[i] = this.myArray[i];
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ public class Schlenglein <T>{
|
||||
this.maxSize = 100;
|
||||
myArray = new Object[this.maxSize];
|
||||
}
|
||||
|
||||
public void add(T t){
|
||||
this.myArray[this.numberOfElements] = t;
|
||||
this.numberOfElements++;
|
||||
@ -19,18 +20,24 @@ public class Schlenglein <T>{
|
||||
|
||||
public T get(){
|
||||
T retValue = (T) this.myArray[0];
|
||||
|
||||
for (int i=0; i<this.numberOfElements; i++){
|
||||
this.myArray[i] = this.myArray[i+1];
|
||||
}
|
||||
|
||||
this.numberOfElements--;
|
||||
attemptDynamicResize();
|
||||
return retValue;
|
||||
}
|
||||
|
||||
public int size(){
|
||||
return this.numberOfElements;
|
||||
}
|
||||
|
||||
public int getArrayLenght(){return this.maxSize;}
|
||||
public int getArrayLenght(){
|
||||
return this.maxSize;
|
||||
}
|
||||
|
||||
public void attemptDynamicResize(){
|
||||
if (numberOfElements < 0.2*maxSize){
|
||||
// Kleiner Machen
|
||||
|
@ -30,7 +30,7 @@ public class Anwendung {
|
||||
int size;
|
||||
|
||||
do {
|
||||
size = (int) (Math.random() * MAX_LENGTH);
|
||||
size = (int) (Math.random() * (MAX_LENGTH+1));
|
||||
} while (size < MIN_LENGTH);
|
||||
|
||||
String output = "";
|
||||
|
Loading…
Reference in New Issue
Block a user