Hello all,
I've used these forums quite a bit in the past year while trying to learn PLCs and HMIs, and I've run across my first problem that I've not been able to find the answer to. I am trying to sort an integer array in ascending order, and I think I have the code correct, but it keeps displaying in descending order. Could you look at my code and see if I have overlooked something?
//Sorts Odd_Polar_Number[] array in ascending order.
for(i = 0 ; i < max_odd ; i++)
{
for(j = 1; j < max_odd - 1 ; j++)
{
if(Odd_Polar_Number > Odd_Polar_Number[j]) //If first array element is greater than second array element.
{
//Swaps array position.
swap = Odd_Polar_Number;
Odd_Polar_Number = Odd_Polar_Number[j];
Odd_Polar_Number[j] = swap;
}
}
}
Thanks!
I've used these forums quite a bit in the past year while trying to learn PLCs and HMIs, and I've run across my first problem that I've not been able to find the answer to. I am trying to sort an integer array in ascending order, and I think I have the code correct, but it keeps displaying in descending order. Could you look at my code and see if I have overlooked something?
//Sorts Odd_Polar_Number[] array in ascending order.
for(i = 0 ; i < max_odd ; i++)
{
for(j = 1; j < max_odd - 1 ; j++)
{
if(Odd_Polar_Number > Odd_Polar_Number[j]) //If first array element is greater than second array element.
{
//Swaps array position.
swap = Odd_Polar_Number;
Odd_Polar_Number = Odd_Polar_Number[j];
Odd_Polar_Number[j] = swap;
}
}
}
Thanks!