Skip to content

Instantly share code, notes, and snippets.

@l3kn
Created August 3, 2014 14:41
Show Gist options
  • Save l3kn/eef4f30e27812f54984d to your computer and use it in GitHub Desktop.
Save l3kn/eef4f30e27812f54984d to your computer and use it in GitHub Desktop.
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