Problem implementing sorting algorithm in C with an array of structs
- by dilog
Well here is my little problem, first my code:
struct alumn {
char name[100];
char lastname[100];
int par;
int nota;
};
typedef struct alumn alumn;
int bubble(alumn **arr, int length)
{
int i,j;
alumn *temp;
for (i=0; i<=length-2; i++) {
for (j=i+1; j<=length-1;j++) {
if ((*arr)[i].nota > (*arr)[j].nota) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main(int argc, char **argv)
{
alumn *alumns;
... here goes some other code ...
bubble(&alumns,totalAlumns);
return 0;
}
My problem is that this algorith is not sorting anything. I'm having a hard time doing the swap, i tried everything but nothing works :( . Any help???
struct alumn {
char name[100];
char lastname[100];
int par;
int nota;
};
typedef struct alumn alumn;
int bubble(alumn **arr, int length)
{
int i,j;
alumn *temp;
for (i=0; i<=length-2; i++) {
for (j=i+1; j<=length-1;j++) {
if ((*arr)[i].nota > (*arr)[j].nota) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main(int argc, char **argv)
{
alumn *alumns;
... here goes some other code ...
bubble(&alumns,totalAlumns);
return 0;
}
My problem is that this algorith is not sorting anything. I'm having a hard time doing the swap, i tried everything but nothing works :( . Any help???