refactoring

This commit is contained in:
jutta 2020-11-15 17:47:26 +01:00
parent 98abf5c8e9
commit 91c0e69df6
6 changed files with 49 additions and 13 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="false" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/GDP-Uebungen.iml" filepath="$PROJECT_DIR$/GDP-Uebungen.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

11
GDP-Uebungen.iml Normal file
View 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$/GDP_Gesamt/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,8 +5,8 @@ import java.util.Arrays;
public class Aufgabe4 {
public static void main(String[] args) {
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};
int timeout = 150; // milliseconds
int[] testValues = {2,34,134,4,53,11,87,142,742,115,00,411,61,33,23456,2346,12,4562,4562,56245,62456,2456,24562};
Arrays.sort(testValues);
for (int value:testValues){
int result = binarySearch(testValues,value, timeout);
@ -17,25 +17,27 @@ public class Aufgabe4 {
System.out.println("Searching for " + value);
printArray(inputArray);
int res=-1;
int rangeMax=inputArray.length-1, rangeMin=0,center,modulo;
int rangeMax=inputArray.length-1, rangeMin=0,center=0;
long lastdate=0;
while(true){
while(res < 0){
Date date = new Date();
long deltaT = date.getTime()-lastdate;
if(deltaT>timeout) {
lastdate = date.getTime();
modulo = (rangeMax - rangeMin) % 2;
center = rangeMin + (rangeMax - rangeMin) / 2;
infoGraphic( value, center, rangeMin, rangeMax, modulo, inputArray);
infoGraphic(value, center, rangeMin, rangeMax, rangeMax, inputArray);
if (value == inputArray[center]) {
res = center;
break;
}
else if (value <= inputArray[center])
rangeMax = center-modulo;
else
rangeMin = center+modulo;
} else if (value > inputArray[center]) {
rangeMin = center;
center += (rangeMax+1 - rangeMin) / 2; // round up
// center = (rangeMax+1 + rangeMin) / 2; // round up
} else {
rangeMax = center;
center -= (rangeMax+1 - rangeMin) / 2;
//center -= (center+1 - rangeMin) / 2;
// center = (rangeMax + rangeMin) / 2;
}
}
}
return res;
}