Created
August 3, 2014 14:41
-
-
Save l3kn/eef4f30e27812f54984d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class MinMax extends Thread | |
{ | |
int[] data; | |
boolean computeMin; | |
public int result = 0; | |
public MinMax(int[] f, boolean min){ | |
data = f; | |
computeMin = min; | |
} | |
public void compute() { | |
result = data[0]; | |
for (int i = 1; i < data.length; i++) | |
{ | |
if (computeMin) { | |
if (data[i] < result) result = data[i]; | |
} else { | |
if (data[i] > result) result = data[i]; | |
} | |
} | |
} | |
public void run() { | |
compute(); | |
} | |
} | |
public class MyProg { | |
public static void main(String[] args) { | |
int[] a = {23,10,3,49,7,5,123,32,92,17}; | |
MinMax a1 = new MinMax(a, true); | |
MinMax a2 = new MinMax(a, false); | |
a1.run(); //Berechnung 1 | |
a2.run(); //Berechnung 2 | |
try { | |
a1.join(); | |
a2.join(); | |
} | |
catch(InterruptedException e) | |
{ } | |
System.out.println("Min: " + a1.result + ", Max: " + a2.result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment