diff --git a/GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe4.java b/GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe4.java index dcbb780..11fae40 100644 --- a/GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe4.java +++ b/GDP_Gesamt/src/Uebungen/Uebung5/Aufgabe4.java @@ -5,7 +5,7 @@ import java.util.Arrays; public class Aufgabe4 { public static void main(String[] args) { - int timeout = 150; // milliseconds + int timeout = 60; // milliseconds int[] testValues = {2,34,134,4,53,11,87,142,742,115,00,411,61,33,23456,2346,12,6234562,4562,4562,56245,62456,2456,24562,1,1345,13451,435,1345,1345,134,51345,134513,451,345}; Arrays.sort(testValues); for (int value:testValues){ @@ -25,24 +25,16 @@ public class Aufgabe4 { if(deltaT>timeout) { lastdate = date.getTime(); modulo = (rangeMax - rangeMin) % 2; - center = rangeMin + (rangeMax - rangeMin) / 2 + modulo; + center = rangeMin + (rangeMax - rangeMin) / 2; infoGraphic( value, center, rangeMin, rangeMax, modulo, inputArray); if (value == inputArray[center]) { res = center; break; } - else if (value == rangeMax){ - res = rangeMax; - break; - } - else if (value == rangeMin){ - res = rangeMin; - break; - } - else if (value < inputArray[center]) - rangeMax = center; - else if (value > inputArray[center]) - rangeMin = center; + else if (value <= inputArray[center]) + rangeMax = center-modulo; + else + rangeMin = center+modulo; } } return res; @@ -64,8 +56,12 @@ public class Aufgabe4 { int maxlength=maxLength(array); System.out.print("P|"); for(int i=0; i,C", maxlength, false)); + else if(i==center) + System.out.print(fixedLengthString("C", maxlength, false)); else if(i==max) System.out.print(fixedLengthString("<", maxlength, false)); else if(i==min) @@ -73,7 +69,7 @@ public class Aufgabe4 { else System.out.print(fixedLengthString(" ", maxlength, false)); } - System.out.println(" MOD: "+modulo); + System.out.println("center: "+center+" MOD: "+modulo+" min: "+min+" max:"+max); } public static String fixedLengthString(String string, int length){ return fixedLengthString( string, length, true);