I have to sort a linked list from greatest value to the smallest. But the way I'm doing is not working. Can somebody please help me?
This is the structures I have:
typedef struct{
int identificador;
char nome[50];
float comissao;
float salario;
}Vendedor;
typedef struct celulav{
Vendedor vendedor;
struct celulav *prox;
}CelulaV;
typedef struct{
CelulaV *primeiro;
CelulaV *ultimo;
}ListaV;
I want to order "ListaV" by the atribute "comissao" in "Vendedor". From the greatest value to the smallest one.
This is what I did:
void Ordena(ListaV lista, ListaV *lista_nova){
CelulaV *aux;
CelulaV *aux2;
Vendedor v;
aux = lista.primeiro;
aux2 = lista_nova->primeiro;
while(aux->prox != NULL){
v.comissao = aux->vendedor.comissao;
if(aux->prox->vendedor.comissao < v.comissao){
v.comissao = aux->prox->vendedor.comissao;
aux = aux->prox;
}else{
aux = aux->prox;
}
aux2->vendedor = v;
aux2 = aux2->prox;
}
}
But this is not working. I can't identify the error.
