smaller algo
This commit is contained in:
		
							parent
							
								
									3fa88b6a5c
								
							
						
					
					
						commit
						98abf5c8e9
					
				| @ -5,7 +5,7 @@ import java.util.Arrays; | |||||||
| public class Aufgabe4 { | public class Aufgabe4 { | ||||||
| 
 | 
 | ||||||
|     public static void main(String[] args) { |     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}; |         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); |         Arrays.sort(testValues); | ||||||
|         for (int value:testValues){ |         for (int value:testValues){ | ||||||
| @ -25,24 +25,16 @@ public class Aufgabe4 { | |||||||
|             if(deltaT>timeout) { |             if(deltaT>timeout) { | ||||||
|                 lastdate = date.getTime(); |                 lastdate = date.getTime(); | ||||||
|                 modulo = (rangeMax - rangeMin) % 2; |                 modulo = (rangeMax - rangeMin) % 2; | ||||||
|                 center = rangeMin + (rangeMax - rangeMin) / 2 + modulo; |                 center = rangeMin + (rangeMax - rangeMin) / 2; | ||||||
|                 infoGraphic( value, center,  rangeMin,  rangeMax, modulo, inputArray); |                 infoGraphic( value, center,  rangeMin,  rangeMax, modulo, inputArray); | ||||||
|                 if (value == inputArray[center]) { |                 if (value == inputArray[center]) { | ||||||
|                     res = center; |                     res = center; | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|                 else if (value == rangeMax){ |                 else if (value <= inputArray[center]) | ||||||
|                     res = rangeMax; |                     rangeMax = center-modulo; | ||||||
|                     break; |                 else | ||||||
|                 } |                     rangeMin = center+modulo; | ||||||
|                 else if (value == rangeMin){ |  | ||||||
|                     res = rangeMin; |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|                 else if (value < inputArray[center]) |  | ||||||
|                     rangeMax = center; |  | ||||||
|                 else if (value > inputArray[center]) |  | ||||||
|                     rangeMin = center; |  | ||||||
|                 } |                 } | ||||||
|         } |         } | ||||||
|         return res; |         return res; | ||||||
| @ -64,8 +56,12 @@ public class Aufgabe4 { | |||||||
|         int maxlength=maxLength(array); |         int maxlength=maxLength(array); | ||||||
|         System.out.print("P|"); |         System.out.print("P|"); | ||||||
|         for(int i=0; i<array.length;i++){ |         for(int i=0; i<array.length;i++){ | ||||||
|             if(i==center) |             if(i==max&i==center) | ||||||
|                 System.out.print(fixedLengthString("C", maxlength, false)); |                 System.out.print(fixedLengthString("C,<", maxlength, false)); | ||||||
|  |             else if(i==min&i==center) | ||||||
|  |                 System.out.print(fixedLengthString(">,C", maxlength, false)); | ||||||
|  |              else if(i==center) | ||||||
|  |                  System.out.print(fixedLengthString("C", maxlength, false)); | ||||||
|             else if(i==max) |             else if(i==max) | ||||||
|                 System.out.print(fixedLengthString("<", maxlength, false)); |                 System.out.print(fixedLengthString("<", maxlength, false)); | ||||||
|             else if(i==min) |             else if(i==min) | ||||||
| @ -73,7 +69,7 @@ public class Aufgabe4 { | |||||||
|             else |             else | ||||||
|                 System.out.print(fixedLengthString(" ", maxlength, false)); |                 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){ |     public static String fixedLengthString(String string, int length){ | ||||||
|         return fixedLengthString( string,  length, true); |         return fixedLengthString( string,  length, true); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user