Problem implementing sorting algorithm in C with an array of structs

Posted by dilog on Stack Overflow See other posts from Stack Overflow or by dilog
Published on 2010-04-04T02:40:52Z Indexed on 2010/04/04 2:43 UTC
Read the original article Hit count: 313

Filed under:
|
|
|

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???

© Stack Overflow or respective owner

Related posts about c

    Related posts about bubble