Hi everyone,
First of all, since I'm Portuguese I may do some grammatical errors, so sorry for that.
I'm programming in C a program to order a structure. This program is a work that I need to do for Numerical Analyses.
I don't know why, but it works great sometimes (with some points), but sometimes it acts backwards, instead of crescent order, it do decrescent order.
this is my function:
Code:
void ordenar_pontos (interpolacao polacao[], int pola)
{
int ini, av;
interpolacao temp;
for(ini = 0;ini < pola-1; ini++)
{
for(av=ini+1;av < pola; av++)
{
if(polacao[av].x > polacao[ini].fx)
{
temp.x = polacao[ini].x;
temp.fx = polacao[ini].fx;
polacao[ini].x = polacao[av].x;
polacao[ini].fx = polacao[av].fx;
polacao[av].x = temp.x;
polacao[av].fx = temp.fx;
}
}
}
}
The int "pola" is the number of points in "polacao", so it goes to polacao[pola-1].