Job4Suprmn
asked on
Logic Error
I think I have a logic error in here but I can't figure out what it is, anyone have a clue?
The method is to sort an array of double values.
/** The method for sorting the numbers */
static void selectionSort(double[] list) {
for (int i = list.length - 2; i >= 1; i--) {
// Find the maximum in the list[0..i]
double currentMax = list[0];
int currentMaxIndex = 0;
for (int j = 1; j <= i; j++) {
if (currentMax < list[j]) {
currentMax = list[j];
currentMaxIndex = j;
}
}
// Swap list[i] with list[currentMaxIndex] if necessary;
if (currentMaxIndex != i) {
list[currentMaxIndex] = list[i];
list[i] = currentMax;
}
}
}
}
The method is to sort an array of double values.
/** The method for sorting the numbers */
static void selectionSort(double[] list) {
for (int i = list.length - 2; i >= 1; i--) {
// Find the maximum in the list[0..i]
double currentMax = list[0];
int currentMaxIndex = 0;
for (int j = 1; j <= i; j++) {
if (currentMax < list[j]) {
currentMax = list[j];
currentMaxIndex = j;
}
}
// Swap list[i] with list[currentMaxIndex] if necessary;
if (currentMaxIndex != i) {
list[currentMaxIndex] = list[i];
list[i] = currentMax;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:°)
void sortArray()
{
for(i=0; i<MAX; i++)
{
for(j=i+1;j<MAX;j++)
{
sort(number[i],number[j]);
number[i]=a;
number[j]=b;
}
}
}
void shuffle()
{
for(i=0; i<MAX; i++)
{
j=(int)(Math.random()*MAX)
if(i!=j)
{
int temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
}
R.K