I've been writing a piece of code that will use a brute force approach to find 50 exponential equations that fit 5 points (x,y) that i've entered. The code is fine and works without a glitch.. The problem is when i try to make it keep a record of the 50 best equations. This sort routine is the one i've been using.. I've put it in its own test class just to make easier to follow. The current problem is it ends up displaying something completely unwarranted and the array ends up with only two different values.

``````public class sortTest{
public static void main(String [] args)
{
int [][] best = new int; //50 best equations. the three placeholders are b,c,euclid in the equation y(t) = 10*b^(t*c). euclid is the euclidean distance between the equation and the points i've given it. The smaller it is, the better the equation.
int tempcomp [] = new int; //to temporarily store new equations
boolean sorted;
for(int index = 0; index<best.length; index++){
best[index] = 100+index;
best[index] = 100+index;
best[index]= 100+index;
}
for(int c = 0; c<best.length; c++)
{
tempcomp = 100-c;
tempcomp = 100-c;
tempcomp= 100-c;
if(tempcomp<best)
best = tempcomp;
sorted = false;
while (!sorted) {
sorted = true;  // assume this is last pass over array
for (int index=0; index<best.length-1; index++) {
if (best[index] > best[index+1]) {
// exchange elements
tempcomp = best[index];  best[index] = best[index+1];  best[index+1] = tempcomp;
sorted = false;  // after an exchange, must look again
}
}
}
}
}
}``````

Thanks for lookin!
Khodeir

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.